[Chicago-talk] How to subvert error message.

Jonathan Rockway jon at jrock.us
Wed Jul 12 08:33:25 PDT 2006

It might be more concise/readable to do this:

    close *STDERR;
    `ls /nonexistent`; # or whatever
else {
    print {*STDERR} "stderr still works here\n";
print {*STDERR} "and here\n"

This, BTW, is inconsistent with the description in perldoc ("fds are 
shared", it says).

Jonathan Rockway

Jess Balint wrote:
> Richard,
> Yet another way is to dup the stderr onto a new fd and then run your
> command. You can restore it afterwards. The following example dups stderr
> onto olderr, then opens stderr onto /dev/null. The command "ls /xxx" is run
> and no error output is displayed. The stderr fd is then restored by duping
> olderr back onto stderr and the command "ls /yyy" is run with the error
> output visible. (It's not the coolest one-liner ;)
> perl -e'open(OLDERR, ">&STDERR");open(STDERR, ">/dev/null");system("ls
> /xxx");close(STDERR);open(STDERR, ">&OLDERR");system("ls /yyy");'
> ________________________________________
> Hello All,
> Is there a way to execute a system command with out the console printing an
> error message?  I wan't to do system("play soundfile.wav") but I do not want
> the error message to print out if the file cannot be played.  
> Any help would be greatly appreciated.
> Thanks in advance,
> Richard
> Your beliefs become your thoughts. Your thoughts become your words. Your
> words become your actions. Your actions become your habits. Your habits
> become your values. Your values become your destiny. -- Mahatma Gandhi
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk

More information about the Chicago-talk mailing list