|
|
Copying stdout to file while leaving on screen...?
|
|
|
|
Forum Regular
Join Date: Jun 2007
Status:
Offline
|
|
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
|
|
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
|
|
|
|
|
|
|
|
|
Forum Regular
Join Date: Jun 2007
Status:
Offline
|
|
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
|
|
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?
|
|
|
|
|
|
|
|
|
Forum Regular
Join Date: Jun 2007
Status:
Offline
|
|
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
|
|
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
|
|
|
|
|
|
|
|
|
Forum Regular
Join Date: Jun 2007
Status:
Offline
|
|
Aaaaah, excellent, thank you. I didn't realize that it would still output to stdout by default. Much appreciated!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|