1st process' exit code

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Let's say I have two programs: 'foo' and 'bar'. 'foo' always returns an
exit code of 10. 'bar' always exits normally (i.e. returns 0).

If I do: `foo | bar` in my shell, the shell will return 10.

If I do: exec('foo | bar', $ignoreMe, $returnCode) in PHP, $returnCode
will contain 0.

Is there a way to detect a pipe's first process' exit code in PHP ?

Background info and an idea: my shell is tcsh. In the above example,
tcsh and csh report the 10 exit code, whereas bash and sh would return
0. Thus, the above question *might* be equivalent to: "Is there a way to
specify in which shell 'exec' should execute commands?"

Thanks in advance...

I am dae3 and I approve my own message.
"Little else matters than to write good code."
                             (Karl Lehenbauer)

Re: 1st process' exit code

Quoted text here. Click to load it

This may be obvious, but....

1) Implement the '|' in your own PHP code, and call proc_open twice.
(or use a Unix socket inbetween but still invoke the programs
independently from your own code)

2) exec("sh 'foo | bar'");

beyond that....ask on tcsh group?


Site Timeline