System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

shell question (intercept stderr output)

 
Highlighted
Ulrich Deiters
Frequent Advisor

shell question (intercept stderr output)

A background process sends messages via stderr to the terminal. How can I duplicate this output to stdout (or elsewhere), so that another process can read the messages, too?

my_prog 2>&1 1>results | tee msgfile 1>&2 |&

with periodic inspection of msgfile works, but is slow. Is there a better way? Thanks in advance for your help.
2 REPLIES 2
Highlighted
Adam J Markiewicz
Trusted Contributor

Re: shell question (intercept stderr output)

Hi

1. How about:
mkfifo msgfifo
and than something like
my_prog 2>msgfifo
or more complicated construction with this?
Disadvantage: 'writes' to fifo are blocked until the reader is attached.

2. tail -f msgfile
scans every second a file and prints only what was appended after previous scan.


Good luck

Adam
I do everything perfectly, except from my mistakes
Highlighted
Steven E. Protter
Exalted Contributor

Re: shell question (intercept stderr output)

Here is an offbeat idea, probably not the best

In another terminal session, run this.

tail -f msgfile

It will show output as it hits the file.

I am sure there is some slick way to do it on the command line, but my way is simple and it would work unless I'm logged in on a console.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com