Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Copying stdout to file while leaving on screen...?

Copying stdout to file while leaving on screen...?
Thread Tools
Forum Regular
Join Date: Jun 2007
Status: Offline
Reply With Quote
May 19, 2009, 12:50 AM
 
Hi All,

Is there any quality mechanism by which to have 'stdout' show up as well as be piped to file? In the past I've been used to either/or, but in this particular case, it's interactive, so I need it to show up on screen as well as be logged to a file.

Best.
     
Mac Elite
Join Date: Oct 1999
Location: San Jose, Ca
Status: Offline
Reply With Quote
May 19, 2009, 12:24 PM
 
What language/environment are you using? If we are talking about shell scripts then using '/usr/bin/tee' (man tee) will do this for you. If you are using a C-based language then you can either have two printf/sprintf commands (or make your own function that does the same thing), or can use ASL (man asl). I have an article about how I have wrapped ASL to make it do what I want that I wrote up:

wrangling macs: Improving on NSLog
     
gberz3  (op)
Forum Regular
Join Date: Jun 2007
Status: Offline
Reply With Quote
May 19, 2009, 04:59 PM
 
I apologize. I'm using a bash shell. Yes, I actually came across 'tee' a bit later. Thanks for that input. Although, I must admit I'm a bit confused that you must use parenthesis and whatnot to pipe to tee then to a file. I would think that tee could simply output to /dev/tty as well as a file without jumping through any hoops.

*shrug*

Oh well, at least it works. Thanks again.
     
Mac Elite
Join Date: Oct 1999
Location: San Jose, Ca
Status: Offline
Reply With Quote
May 19, 2009, 06:16 PM
 
I am not sure what problem you are referring to. I don't generally use parenthesis with 'tee'. Could you post some sample code that you think requires it?
     
gberz3  (op)
Forum Regular
Join Date: Jun 2007
Status: Offline
Reply With Quote
May 19, 2009, 10:40 PM
 
Sure:

Code:
((openssl s_client -connect pop.secureserver.net:995) | tee /dev/tty) > /Users/username/Desktop/12345.txt
If I do it without the parenthesis and simply append '/dev/tty' and '/12345.txt' to the end of the tee command, I get occasional duplicate output on the screen when sending commands. For instance, most non-email responses from the server are received in duplicate (e.g. "+OK" and "-ERR" occasionally come in duplicates).
     
Mac Elite
Join Date: Oct 1999
Location: San Jose, Ca
Status: Offline
Reply With Quote
May 20, 2009, 12:32 PM
 
I think that this is a simpler way of doing the same thing:
Code:
openssl s_client -connect pop.secureserver.net:995 | tee /Users/username/Desktop/12345.txt
     
gberz3  (op)
Forum Regular
Join Date: Jun 2007
Status: Offline
Reply With Quote
May 20, 2009, 09:02 PM
 
Aaaaah, excellent, thank you. I didn't realize that it would still output to stdout by default. Much appreciated!
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 02:18 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2