?
Solved

sending the STDOUT and the STDERR to programs in the shell

Posted on 2007-03-29
6
Medium Priority
?
362 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
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 500 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
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.
Suggested Courses

752 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