Solved

sending the STDOUT and the STDERR to programs in the shell

Posted on 2007-03-29
6
343 Views
Last Modified: 2013-12-26
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?
0
Comment
Question by:oleber
  • 2
  • 2
  • 2
6 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18815885
0
 
LVL 10

Author Comment

by:oleber
ID: 18817225
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.
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18817502
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
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 84

Expert Comment

by:ozo
ID: 18827893
(perl -e 'print "aaa\n"; warn "bbb\n"' | perl -ne 'print "   $_"; ') 3>&1 1>&2 2>&3 3>&-  | perl -ne 'print "** $_"'
0
 
LVL 10

Author Comment

by:oleber
ID: 18827954
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.

0
 
LVL 84

Accepted Solution

by:
ozo earned 125 total points
ID: 18829162
(perl -e '$|=1; 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 "** $_"'
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now