LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices



Reply
 
Search this Thread
Old 07-19-2005, 06:40 PM   #1
ivj
Member
 
Registered: Jul 2004
Posts: 61

Rep: Reputation: 15
How do I forward standard and error output into same file?


I run my program using the following command:

nohup sh -c "exec $RUN_CMD >>$NBWA_HOME/log/spider.log" >/dev/null &

And when my program crashed there was no error messages in spider.log. I assume this is because all those message went into the error stream which was the terminal which I couldn't see because it was ran in the background...

How can I forward both standard output and error output into the same file?

Thanks!
 
Old 07-19-2005, 07:24 PM   #2
IamDaniel
Member
 
Registered: Mar 2003
Location: Sungai Petani
Distribution: Slackware
Posts: 143

Rep: Reputation: 15
Re: How do I forward standard and error output into same file?

Quote:
Originally posted by ivj
I run my program using the following command:

nohup sh -c "exec $RUN_CMD >>$NBWA_HOME/log/spider.log" >/dev/null &

And when my program crashed there was no error messages in spider.log. I assume this is because all those message went into the error stream which was the terminal which I couldn't see because it was ran in the background...

How can I forward both standard output and error output into the same file?

Thanks!
Because you redirect everything to `/dev/null' at the end of the line.

According to bash manual:

Quote:
...
Redirecting Standard Output and Standard Error
Bash allows both the standard output (file descriptor 1)
and the standard error output (file descriptor 2) to be
redirected to the file whose name is the expansion of word
with this construct.

There are two formats for redirecting standard output and
standard error:

&>word
and
>&word

Of the two forms, the first is preferred. This is seman-
tically equivalent to

>word 2>&1
...
Thus, your command should be:

Code:
nohup sh -c "exec $RUN_CMD &>$NBWA_HOME/log/spider.log" &
Hope this help.

Last edited by IamDaniel; 07-19-2005 at 07:27 PM.
 
Old 07-19-2005, 07:29 PM   #3
IamDaniel
Member
 
Registered: Mar 2003
Location: Sungai Petani
Distribution: Slackware
Posts: 143

Rep: Reputation: 15
Opppsss...I didn't notice the double quote `" "` within the `sh -c'...

but anyway, it should works...
 
Old 07-19-2005, 07:30 PM   #4
ivj
Member
 
Registered: Jul 2004
Posts: 61

Original Poster
Rep: Reputation: 15
That seems to work thanks!

Although now I have a "nohup: appending output to nohup.out"...

Is there any way I can move that file?
 
Old 07-19-2005, 08:49 PM   #5
IamDaniel
Member
 
Registered: Mar 2003
Location: Sungai Petani
Distribution: Slackware
Posts: 143

Rep: Reputation: 15
Quote:
Originally posted by ivj
That seems to work thanks!

Although now I have a "nohup: appending output to nohup.out"...

Is there any way I can move that file?
Code:
~$ nohup sh -c "exec ls &>_filename_.log" > /dev/null
should do the tricks...
 
Old 07-19-2005, 09:30 PM   #6
ivj
Member
 
Registered: Jul 2004
Posts: 61

Original Poster
Rep: Reputation: 15
ohh get it now thx :P
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting 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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
error in gcc / g++ standard file maheshbmane Programming 6 09-02-2005 09:30 PM
how to enumerate first line of text file to standard output? zero79 Linux - General 1 07-07-2004 07:37 PM
cant see .forward file in home directory >> mail forward/copy steve_babbage Linux - Newbie 0 03-02-2004 07:25 AM
How to redirect standard output of piped command to log file andrewstr Linux - General 10 02-04-2004 03:07 PM
Using echo to output a string to a file with forward slashs chrisk5527 Linux - General 15 06-21-2003 03:04 PM


All times are GMT -5. The time now is 03:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration