Using exec with & - what might I get back? [message #173655] |
Sun, 24 April 2011 11:03 |
Tim Streater
Messages: 328 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
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?
Thx,
--
Tim
"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
|
|
|
Re: Using exec with & - what might I get back? [message #173662 is a reply to message #173655] |
Mon, 25 April 2011 15:18 |
Peter H. Coffin
Messages: 245 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
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.
--
59. I will never build a sentient computer smarter than I am.
--Peter Anspach's list of things to do as an Evil Overlord
|
|
|
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: 0
|
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
|
|
|