Solved

sending the STDOUT and the STDERR to programs in the shell

Posted on 2007-03-29
6
358 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 143

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 143

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
Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

 
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

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 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