in reply to System Calls with backticks

cat2014 susspected correct. I ran the following test on my machine (Solaris 7) :

/usr/sbin/ufsdump 0uf /bar /foo
i got output, and aborted with Ctrl+C

Then, i tried the following :
/usr/sbin/ufsdump 0uf /bar /foo 2> stderr.out
Nothing printed to screen, aborted with Ctrl+C

This proves that ufsdump writes to STDERR, not STDOUT. There are two fixes.
  1. You could add 2>&1 to the end of your command line. This would re-direct STDERR into STDOUT, and the backticks would work.
  2. You could fork off a child, and re-open STDERR to point to STDOUT, then exec the process. A bit longer method, but does not require the use of a shell (which is non-portable ... not that ufsdump for Win32 is really there.)

$ perl -e 'do() || ! do() ;' Undefined subroutine &main::try

Replies are listed 'Best First'.
Re: Re: System Calls with backticks
by kal (Hermit) on Jan 07, 2002 at 16:02 UTC

    There is another option, one which was brought up in the Chatterbox recently. The IPC::Open3 module will automate much of option 2; but is more complex than option 1.

    The choice is essentially between ease of implementation and need to keep stdout separate from stderr. Since stdout seems to be completely empty in this case, I would choose option 1, which is also the easiest to implement.