FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Using exec with & - what might I get back?
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Using exec with & - what might I get back? [message #173655] Sun, 24 April 2011 11:03 Go to next message
Tim Streater is currently offline  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 Go to previous messageGo to next message
Peter H. Coffin is currently offline  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 Go to previous message
Tim Streater is currently offline  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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Stats comp.lang.php (last 7 days)
Next Topic: Adding a CDATA section
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Sep 20 12:30:42 GMT 2024

Total time taken to generate the page: 0.01844 seconds