Redirecting Stderr to Screen AND A File At The Same Time
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Shell > Redirecting Stderr to Screen AND A File At The Same Time




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Redirecting Stderr to Screen AND A File At The Same Time  
absinth


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-31-05 08: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






[ Post a follow-up to this message ]



    Re: Redirecting Stderr to Screen AND A File At The Same Time  
c0ldbyte


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-31-05 08: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 )





[ Post a follow-up to this message ]



    Re: Redirecting Stderr to Screen AND A File At The Same Time  
Bill Seivert


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-31-05 08: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






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 11:23 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register