Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #1280 > unrolled thread

Using exec with & - what might I get back?

Started byTim Streater <timstreater@waitrose.com>
First post2011-04-24 12:03 +0100
Last post2011-04-25 19:11 +0100
Articles 3 — 2 participants

Back to article view | Back to comp.lang.php


Contents

  Using exec with & - what might I get back? Tim Streater <timstreater@waitrose.com> - 2011-04-24 12:03 +0100
    Re: Using exec with & - what might I get back? "Peter H. Coffin" <hellsop@ninehells.com> - 2011-04-25 10:18 -0500
      Re: Using exec with & - what might I get back? Tim Streater <timstreater@waitrose.com> - 2011-04-25 19:11 +0100

#1280 — Using exec with & - what might I get back?

FromTim Streater <timstreater@waitrose.com>
Date2011-04-24 12:03 +0100
SubjectUsing exec with & - what might I get back?
Message-ID<timstreater-545AAF.12031324042011@news.individual.net>
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

[toc] | [next] | [standalone]


#1288

From"Peter H. Coffin" <hellsop@ninehells.com>
Date2011-04-25 10:18 -0500
Message-ID<slrnirb469.2mh.hellsop@nibelheim.ninehells.com>
In reply to#1280
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

[toc] | [prev] | [next] | [standalone]


#1289

FromTim Streater <timstreater@waitrose.com>
Date2011-04-25 19:11 +0100
Message-ID<timstreater-11E22F.19113325042011@news.individual.net>
In reply to#1288
In article <slrnirb469.2mh.hellsop@nibelheim.ninehells.com>,
 "Peter H. Coffin" <hellsop@ninehells.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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web