ash - exit code for a piped process

Tito farmatito at tiscali.it
Sat Aug 4 14:24:18 UTC 2007


On Saturday 04 August 2007 15:45:56 Loïc Grenié wrote:
> 2007/8/4, Alexander Kriegisch <Alexander at kriegisch.name>:
> > I would like to determine the exit code of 'foo' in
> > foo | bar
> >
> > I bash there is the PIPESTATUS array, but in ash (which I must use)
> > there is no such thing as PIPESTATUS or arrays. Is there any canonical
> > way or at least a workaround to achieve both piping the foo's output
> > into bar unconditionally *and* determining foo's exit code?
> 
> x=`((( foo 3>&- 4>&- ); echo $? >&3)| bar >&4  3>&- 4>&-) 3>&1` 4>&1
> 
>   should do the trick. The exit code of foo is in x, the output of bar
>   goes to the output of the command.
> 
>       Hope this helps.
> 
>          Loïc

foo > out.file
ret=$?
cat out.file | bar
# rm out.file

Untested. Just an idea...........

Ciao,
Tito



More information about the busybox mailing list