in reply to redirecting STDERR from shell commands

You can redirect STDERR like this:
system("$cmd 2>$err");

Replies are listed 'Best First'.
Re: Re: redirecting STDERR from shell commands
by pike (Monk) on Sep 07, 2001 at 18:01 UTC
    Fine for sh / bash / ksh, but will this work also for csh /tcsh?

    Anyway, it seems a waste to me to write to a file and then read it rather than opening a pipe. I just stumbled across the following piece of code:

    open (CMD, "$cmd 2>&1|"); $errStr = <CMD>;

    but it looks to me like this also involves the syntax of the underlying shell, or am I wrong?

      Yes, it does. That is why Perl always uses /bin/sh for system (unless Perl can handle it itself). It never uses csh, tcsh, etc.

      Of course, if you are on a system that doesn't have /bin/sh, then this might not work. For example, Win9x's cmd doesn't know about 2>&1 (but WinNT's command.exe does). This is one big reason why building CPAN modules under Win9x often doesn't work.

              - tye (but my friends call me "Tye")