|
Home > Archive > Unix Shell > March 2005 > Redirecting Stderr to Screen AND A File At The Same Time
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Redirecting Stderr to Screen AND A File At The Same Time
|
|
| absinth 2005-03-31, 3:01 am |
| How do I redirect the output of my script's standard error both to the
terminal and to a file?
For example I've tried:
../eimScTest.ksh 2>blah.out 2>&1
To no avail
| |
| c0ldbyte 2005-03-31, 3:01 am |
| -----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 2005-03-31, absinth <absinth@gmail.com> wrote:
> How do I redirect the output of my script's standard error both to the
> terminal and to a file?
>
> For example I've tried:
> ./eimScTest.ksh 2>blah.out 2>&1
>
>
> To no avail
>
First of all you need to get the tty that the message should be printed
to. For example ( echo "Hello World!" >`tty` ). notice command tty in
back quotes ``, well those are telling the whole command to process
the tty command first. Now that we have the console part taken care of
on to bigger and better things like putting it in a file at the same
time. For this to happen Im sure there are multiple ways of doing it
but number one is break it into two commands and set a variable to hold
the output of the script first and then echo $VARIABLE into the terminal
and the file.
Best of luck,
--c0ldbyte
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (FreeBSD)
Comment: http://pgp.mit.edu:11371/pks/lookup...arch=0xF7DF979F
Comment: Fingerprint = D1DC 0AA4 1C4E EAD4 24EB 7E77 B261 50BA F7DF 979F
iD8DBQFCS5pVsmFQuvffl58RAjfaAJ922BorlkYM
SrpnKL/H2+CF5MmBmACfRcqd
BHlUYw44Dg52OkX8STbXdmE=
=8TCF
-----END PGP SIGNATURE-----
--
( When in doubt, use brute force. -- Ken Thompson 1998 )
| |
| Bill Seivert 2005-03-31, 3:01 am |
|
absinth wrote:
> How do I redirect the output of my script's standard error both to the
> terminal and to a file?
>
> For example I've tried:
> ./eimScTest.ksh 2>blah.out 2>&1
>
>
> To no avail
>
Try:
../eimScTest.ksh 2>&1 | tee blah.out
That will send both stdout and stderr to blah.out and the terminal.
To ONLY have stderr go to blah.out, do one of these:
# No stdout printed
../eimScTest.ksh 2>&1 1>/dev/null | tee blah.out
# stdout to file std.out
../eimScTest.ksh 2>&1 1>std.out | tee blah.out
The pipe (|) only passes stdout through it, so the 2>&1 says send stderr
to the same place as stdout. The tee says create a file and send stdout
to the next pipeline (if any) or the terminal.
Bill Seivert
|
|
|
|
|