in reply to redirecting standard output and standard error

Skeeve has shown how to get rid of the stderr output from the system call.

The error message is saying that when "system()" invokes a shell to run your "java -version" command, the shell is unable to find an application called "java" in its current PATH. But I don't understand the "UX:" part.

What operating system and shell are you using? This might account for why the redirection didn't work as expected. On my bsd-based darwin OS, the first of the two commands below produces an error message on the console, but the second does not -- meanwhile, a freebsd system behaves differently:

perl -e 'system( "foo > junk" ); # prints: # sh: line 1: foo: command not found (on darwin) # foo: not found (on freebsd 6.1) perl -e 'system( "foo > junk 2>/dev/null" ); # no output on darwin # still prints "foo: not found" on freebsd
I'm not sure if that's a difference in how Perl was built on the two machines I happened to be using, or whether it's a matter of how the shells work.

It may also be relevant that the ability to redirect stderr and stdout separately is only available for Bourne-style shells (sh, bash, ksh, zsh); in "c-style" shells ("csh" and any others like it), you can redirect stdout, and you can have stderr included with stdout when redirecting stdout, and that's all you can do ( 2> errlog is not supported, which is a big reason why I never use csh).

Replies are listed 'Best First'.
Re^2: redirecting standard output and standard error
by Skeeve (Parson) on Sep 04, 2006 at 15:44 UTC
    I guess system("something 2>/dev/null") should redirect the error output of "something". Not that of the shell calling "something" So I would expect the error to be displayed when "something" isn't available (the error is produced by the shell) and to be suppressed when "something" is available, but produces an error.

    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e