|
Home > Archive > Unix Shell > August 2007 > Will 2&>1 not pipe stderr to stdout?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Will 2&>1 not pipe stderr to stdout?
|
|
| Carfield Yim 2007-08-27, 1:25 pm |
| I am maintaining a Java application that consist of a lot of code
using exception.printstacktrace() to print exception messages to
standard error stream. I am not allowed to update the code to make it
log properly.
Then I try to start my application using script like Java -cp xxx
MainClass > log.txt 2&>1 & so that the exception message will be
logged. However, we found out that the exception message is not
logged. Is there any problem about this approach? How can I log the
standard error stream?
| |
| Scott McMillan 2007-08-27, 7:22 pm |
| On Mon, 27 Aug 2007 18:23:17 -0000, Carfield Yim <carfield@gmail.com>
wrote:
>I am maintaining a Java application that consist of a lot of code
>using exception.printstacktrace() to print exception messages to
>standard error stream. I am not allowed to update the code to make it
>log properly.
>
>Then I try to start my application using script like Java -cp xxx
>MainClass > log.txt 2&>1 & so that the exception message will be
>logged. However, we found out that the exception message is not
>logged. Is there any problem about this approach? How can I log the
>standard error stream?
.... 2>&1
Scott McMillan
| |
| Lew Pitcher 2007-08-27, 7:22 pm |
| On Aug 27, 2:23 pm, Carfield Yim <carfi...@gmail.com> wrote:
> I am maintaining a Java application that consist of a lot of code
> using exception.printstacktrace() to print exception messages to
> standard error stream. I am not allowed to update the code to make it
> log properly.
It shouldn't necessarily take a code update to make your stderr
exception messages into a "proper" log. Rather, you just have to
adjust the script that launches the process, so as to pipe stderr into
a suitable logging tool.
> Then I try to start my application using script like
> Java -cp xxx MainClass > log.txt 2&>1 &
> so that the exception message will be
> logged. However, we found out that the exception message is not
> logged.
As others have pointed out, you have a typo that causes stderr not to
be written to your "log.txt" file. The typo has two other side
effects:
1) your Java command is given the additional extraneous argument
"2", and
2) you inadvertantly create a file called "1" in the cwd of the
process that launched the java
command
First off, do you understand why these side effects happened? Do you
understand what the correction to your typo does?
> Is there any problem about this approach? How can I log the
> standard error stream?
Any number of ways:
java -cp xxx MainClass > log.txt 2>&1 &
or
java -cp xxx MainClass > log.txt 2>stderror.log.txt &
or even some
java -cp xxx MainClass 2>&1 >log.txt | logger &
(which will send stdout to your log text file, and stderr to the old
stdout destination to be piped into logger(1) which (with suitable
arguments) will log the text to the syslog)
HTH
--
Lew
| |
| Carfield Yim 2007-08-28, 1:20 am |
| On 8 28 , 2 43 , Scott McMillan <smcmil...@twmi.rr.com> wrote:
> On Mon, 27 Aug 2007 18:23:17 -0000, Carfield Yim <carfi...@gmail.com>
> wrote:
>
>
>
> ... 2>&1
>
> Scott McMillan
Typo, it is 2>&1 already
| |
| Barry Margolin 2007-08-28, 1:20 am |
| In article <1188271999.589148.109090@q4g2000prc.googlegroups.com>,
Carfield Yim <carfield@gmail.com> wrote:
> On 8 28 , 2 43 , Scott McMillan <smcmil...@twmi.rr.com> wrote:
>
> Typo, it is 2>&1 already
Are you sure that exception.printstacktrace() writes to stderr? Maybe
it writes to /dev/tty. Perhaps you should ask in a Java newsgroup.
Are you sure your command line ended with '>log.txt 2>&1'? If you put
these in the wrong order, i.e. '2>&1 >log.txt' then it won't do what you
want.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
|
|
|
|
|