Afficher un message
Vieux 14/03/2008, 16h42   #6
Geoff Clare
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: One file for "stout+sterror" and another for "sterror"; it'spossible?

Jeenu wrote:

> ./script.sh 2>err | tee out >> err
>
> Now the file "err" should have both stdout and stderr. Meantime, the
> file out should contain your stdout only.


No, the err file is likely to be missing some or all of stdout.
That's because the file is opened independently in two processes,
and only one of them opens it in append mode.

For example:

$ (echo OUT; sleep 2; echo ERR >&2) 2>err | tee out >> err
$ cat err
ERR
$ cat out
OUT

To avoid data loss, both processes must open the file in append mode:

$ > err
$ (echo OUT; sleep 2; echo ERR >&2) 2>>err | tee out >> err
$ cat err
OUT
ERR
$ cat out
OUT

Also, this doesn't quite match what the OP asked for, which would be:

$ > out
$ (echo OUT; sleep 2; echo ERR >&2) 2>&1 >>out | tee err >> out
$ cat out
OUT
ERR
$ cat err
ERR

--
Geoff Clare <netnews@gclare.org.uk>
  Réponse avec citation
 
Page generated in 0,04744 seconds with 9 queries