Re: Using exec with & - what might I get back? [message #173663 is a reply to message #173662] |
Mon, 25 April 2011 18:11 |
Tim Streater
Messages: 328 Registered: September 2010
Karma:
|
Senior Member |
|
|
In article <slrnirb469(dot)2mh(dot)hellsop(at)nibelheim(dot)ninehells(dot)com>,
"Peter H. Coffin" <hellsop(at)ninehells(dot)com> wrote:
> On Sun, 24 Apr 2011 12:03:13 +0100, Tim Streater wrote:
>> If I do this:
>>
>> exec ("/path/to/some/prog &", $results, $status);
>>
>> will I ever get anything at all back in $results and $status? Or will
>> $results always be empty and $status always zero?
>
> If /path/to/some/prog is startable (executable, parses, etc.), I
> wouldn't expect any useful outcome in $results or $status. Essentially,
> you're asking it to go into the background. If you want to wait around
> for results, you'll have to drop the &. If you want to check back
> later, that's outside the scope of this question; you'll have to write
> /path/to/some/prog to report back by other means.
That's essentially what I expect, too. Empirically, $status appears to
be zero. My use of exec () is a mixture of with/without the &, for
various reasons.
I have found the hard way that, without the &, I need to do this:
exec ("/path/to/some/prog 2>&1", $results, $status);
otherwise, anything prog outputs to stderr appears in my PHP script's
output stream just as if I'd done echo of the same information.
I also found that if I use & and prog wants to output anything at all,
I'd better redirect *all* output, otherwise prog may hang. In practice I
use /dev/null, thus:
exec ("/path/to/some/prog > /dev/null 2>&1 &", $results, $status);
although one could of course send it to a file.
--
Tim
"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
|
|
|