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
Return to the default flat view Create a new topic Submit Reply
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:
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
[Message index]
 
Read Message
Read Message
Read Message
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:23:08 GMT 2024

Total time taken to generate the page: 0.04818 seconds