in reply to Re: redirecting STDERR from shell commands
in thread redirecting STDERR from shell commands

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?

Replies are listed 'Best First'.
(tye)Re: redirecting STDERR from shell commands
by tye (Sage) on Sep 07, 2001 at 21:46 UTC

    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")