Link to home
Start Free TrialLog in
Avatar of oleber
oleberFlag for Portugal

asked on

sending the STDOUT and the STDERR to programs in the shell

Sending the STDOUT and the STDERR to programs.

I can do:
 perl -e 'print "aaa\n"; warn "bbb\n"' | perl -ne 'print "   $_"'
 perl -e 'print "aaa\n"; warn "bbb\n"' 2| perl -ne 'print "** $_"'

but I can't do bout:

 perl -e 'print "aaa\n"; warn "bbb\n"' | perl -ne 'print "   $_"'  2| perl -ne 'print "** $_"'


Notice that the important part of the question is:
How to use the | and 2| in the some command line?
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Avatar of oleber

ASKER

This isn't a perl question.
the question is:

How to use the | and 2| in the some command line?

Or better, I need the STDOUT to go to one process and the STDERR to another. The perl in this example is just because I'm used to use it, but I can't do it in this project. Just C, the real old C.
I see.
in the shell as such, you need to use the 2&>1 to get the stderr redirected to the stdout.

as I don't use unix alot, I am not sure where to put that:

 perl -e 'print "aaa\n"; warn "bbb\n"' 2&>1 | perl -ne 'print "   $_"'

 perl -e 'print "aaa\n"; warn "bbb\n"' | perl -ne 'print "   $_"' 2&>1
(perl -e 'print "aaa\n"; warn "bbb\n"' | perl -ne 'print "   $_"; ') 3>&1 1>&2 2>&3 3>&-  | perl -ne 'print "** $_"'
Avatar of oleber

ASKER

there is a order problem

The command:
(perl -e 'print "aaa\n"; sleep(1); warn "bbb\n"; sleep(1); warn "ccc\n"' | perl -ne 'print "   $_"; ') 3>&1 1>&2 2>&3 3>&-  | perl -ne 'print "** $_"'

is printing:
** bbb
** ccc
   aaa

in my cygwin.

so it isn't a good solution.

ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial