LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   How do I forward standard and error output into same file? (https://www.linuxquestions.org/questions/linux-software-2/how-do-i-forward-standard-and-error-output-into-same-file-344771/)

ivj 07-19-2005 05:40 PM

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!

IamDaniel 07-19-2005 06:24 PM

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.

IamDaniel 07-19-2005 06:29 PM

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

but anyway, it should works...

ivj 07-19-2005 06:30 PM

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?

IamDaniel 07-19-2005 07:49 PM

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...

ivj 07-19-2005 08:30 PM

ohh get it now thx :P


All times are GMT -5. The time now is 05:08 AM.