Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Redirecting STDOUT and standard error to file

by davidrw (Prior)
on Sep 08, 2005 at 21:01 UTC ( [id://490322]=note: print w/replies, xml ) Need Help??


in reply to Redirecting STDOUT and standard error to file

googling for "tee exit code" i found this that works (source):
(/bin/foo ; echo $? >RES)| tee -a $LOGFILE export ERR=$(cat RES)

I also found this posting (see also man bash and search for PIPESTATUS) that says that this will work:
$ cat test #!/bin/bash echo foo sleep 2 echo bar false $ ./test | tee blah foo [.. seconds later..] bar $ echo ${PIPESTATUS[@]} 1 0 # (so ${PIPESTATUS[0]} should give you the return of the first comma +nd).
But i was unable to get it to work (PIPESTATUS seemed to always have just one element of 0)...

Replies are listed 'Best First'.
Re^2: Redirecting STDOUT and standard error to file
by ikegami (Patriarch) on Sep 08, 2005 at 21:14 UTC

    PIPESTATUS works for me.

    $ uname -s -r FreeBSD 5.4-RELEASE $ bash --version GNU bash, version 2.05b.0(1)-release (i386-portbld-freebsd4.8) Copyright (C) 2002 Free Software Foundation, Inc.

    man bash extract:

    PIPESTATUS
    An array variable (see Arrays below) containing a list of exit status values from the processes in the most-recently-executed foreground pipeline (which may contain only a single command).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://490322]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-19 01:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found