PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Will 2&>1 not pipe stderr to stdout?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Will 2&>1 not pipe stderr to stdout?

Réponse
 
LinkBack Outils de la discussion
Vieux 27/08/2007, 19h23   #1
Carfield Yim
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Will 2&>1 not pipe stderr to stdout?

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?

  Réponse avec citation
Vieux 27/08/2007, 19h43   #2
Scott McMillan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Will 2&>1 not pipe stderr to stdout?

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
  Réponse avec citation
Vieux 27/08/2007, 19h43   #3
Scott McMillan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Will 2&>1 not pipe stderr to stdout?

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
  Réponse avec citation
Vieux 27/08/2007, 20h34   #4
Lew Pitcher
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Will 2&>1 not pipe stderr to stdout?

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

  Réponse avec citation
Vieux 27/08/2007, 20h34   #5
Lew Pitcher
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Will 2&>1 not pipe stderr to stdout?

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

  Réponse avec citation
Vieux 28/08/2007, 04h33   #6
Carfield Yim
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Will 2&>1 not pipe stderr to stdout?

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


Typo, it is 2>&1 already

  Réponse avec citation
Vieux 28/08/2007, 04h33   #7
Carfield Yim
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Will 2&>1 not pipe stderr to stdout?

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


Typo, it is 2>&1 already

  Réponse avec citation
Vieux 28/08/2007, 04h52   #8
Barry Margolin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Will 2&>1 not pipe stderr to stdout?

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:
> > On Mon, 27 Aug 2007 18:23:17 -0000, 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.

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

>
> 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 ***
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 13h24.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,19228 seconds with 16 queries