Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
09-16-2007, 08:11 AM
|
#1
|
Member
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518
Rep:
|
IS it possible to send command output to a file as well as the screen
Hello people,
I've got a program here and i know how to send stderr and stdout to a log file etc, etc, and of course i know if you don't specify a file those outputs will just be shown in the console window, but is it possible to do both at the same time on the same command, so i can see stderr and stdout as normal on the screen but it can also be getting stored at the same time in a log file. I don't know if something like the [ option1 || option2 ] type of thing comes into the equation by meaning option1 AND option2??
Would be cool if this is possible!! and how?
Cheers
|
|
|
09-16-2007, 08:24 AM
|
#2
|
LQ Veteran
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,286
|
Have a look at "man tee".
|
|
|
09-16-2007, 10:02 AM
|
#3
|
Member
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518
Original Poster
Rep:
|
thanks, i've looked at it, but can't get it to workit only prints out stdout i'm using..
bash filename | tee -a log
i looked at the ibm site and they have a method of doing it but it seems complicated for something that should be simple. Thanks for the push in direction
|
|
|
09-16-2007, 10:16 AM
|
#4
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
Quote:
Originally Posted by helptonewbie
thanks, i've looked at it, but can't get it to workit only prints out stdout i'm using..
|
Do you mean you get an empty log? Maybe, your script send messages to stderr only. You can try
Code:
bash filename 2>&1 | tee -a log
|
|
|
09-16-2007, 11:29 AM
|
#5
|
Member
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518
Original Poster
Rep:
|
Thanks, its alwasy the way i did try
bash filename | tee -a log 2>&1
before bothering to post here, should have tried that way to lol, thanks perfect!!!
|
|
|
09-16-2007, 01:11 PM
|
#6
|
Member
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518
Original Poster
Rep:
|
Ahh not so good, i did try it on a little test and thought it would work fine within my program but it doesn't as i guess the way i invoke the commands are a little different.
what i have is a file with a lot of different commands in that can be executed. this works as follows.
PATH=$PATH:/path_to_commandfile
commandfile [argument]
then in the command file is a function and therefore depending on what argument was passed depends on the commands that are run within that file, what i would like to do is get the stdout and stderr onto the output on the screen, so basically where ever commandfile [argument] is run, it already outputs fine to a log file, but i can't see it on the screen even with the tee command i guess because its not sending the output to the right tty or something?? any ideas
|
|
|
09-16-2007, 02:13 PM
|
#7
|
Member
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518
Original Poster
Rep:
|
Its ok all sorted now, thanks to people for their help
Final Result:-
run on screen
screen_pts=`tty`
echo "screen_pts="$screen_pts > file1
run in command file
source file1
command 2>&1 | tee -a log >> $screen_pts
works like a charm
Cheers
|
|
|
All times are GMT -5. The time now is 03:44 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|