in reply to Redirecting and using output from executed program

STDERR is file descriptor 2, STDOUT is descriptor 1. You can redirect it wherever you want:

# no redirection C:\>perl -e "warn 'foo'" foo at -e line 1. # redirect STDERR to FILE (often /dev/null :-) C:\>perl -e "warn 'foo'" 2> out C:\>type out foo at -e line 1. # redirect STDERR to STDOUT C:\>perl -e "warn 'foo'" 2>&1 foo at -e line 1. # redirect STDERR to STDOUT and STDOUT to FILE C:\>perl -e "warn 'foo';print 'bar'">out 2>&1 C:\>type out foo at -e line 1. bar

cheers

tachyon

Replies are listed 'Best First'.
Re^2: Redirecting and using output from executed program
by Hena (Friar) on Sep 30, 2004 at 08:11 UTC
    I don't want to redirect my own scripts STDERR anywhere (unless that is the only option, then obviously I must). I want to redirect/edit the STDERR from the program I execute. Every rediction must be done within script, as the script will be called by others programs eventually.

      It is no different within yor script, just open (T_RES,"@exec 2>&1 |")

        Ah... Ok :). Then I will get both STDERR and STDOUT in same stream. Thats would work, thanks.

        However is it possible to get it into different stream or prepend each line from STDERR or STDOUT with something to allow easier seperation of the STDOUT and STDERR?