Page 1 of 1
exec() command doesn't seem to work
Posted: Mon May 18, 2009 5:59 pm
by TheStoryTeller
Hi, I'm trying to use the exec() command for a background computation. something like this:
It doesn't work.
I then found out that even simple use of exec() is not working.
I tried this:
and also got blank, but when I do this:
I get the right answer on screen.
what am I missing here?
Re: exec() command doesn't seem to work
Posted: Mon May 18, 2009 6:32 pm
by Benjamin
Is php in safe mode? Are you getting any errors?
Note: When safe mode is enabled, you can only execute files within the safe_mode_exec_dir. For practical reasons, it is currently not allowed to have .. components in the path to the executable.
See:
http://us.php.net/manual/en/function.exec.php
Re: exec() command doesn't seem to work
Posted: Mon May 18, 2009 6:39 pm
by TheStoryTeller
I guess I forgot to mention.. I checked the phpinfo() and safe mode is turned off.
Re: exec() command doesn't seem to work
Posted: Mon May 18, 2009 6:53 pm
by Benjamin
Try this:
Code: Select all
echo "exec returned: " . exec('php -r ./child.php > /dev/null', $result, $rcode]) . '<br />';
echo '<pre>' . print_r($result, true) . '</pre>';
echo "Return Code: $rcode<br />";
Re: exec() command doesn't seem to work
Posted: Tue May 19, 2009 5:25 am
by TheStoryTeller
astions, I tries your code and again nothing happens. there's no error message - just nothing is printed.
edited: I was mistaken, something does appear.
Re: exec() command doesn't seem to work
Posted: Tue May 19, 2009 9:47 am
by Benjamin
Copy and paste the output.
Re: exec() command doesn't seem to work
Posted: Tue May 19, 2009 3:05 pm
by TheStoryTeller
astions wrote:Copy and paste the output.
ok, my mistake: something
is written:
Code: Select all
exec returned:
Array
(
)
Return Code: 254
what can you make of this?
Re: exec() command doesn't seem to work
Posted: Tue May 19, 2009 3:12 pm
by Darhazer
The difference between exec() / system() and the ` operator is that the functions return only the last line of the output, and if it is a empty string, or if output is piped to /dev/null, you won't receive anything.
` operator, like the passthru function, return the whole output.
Re: exec() command doesn't seem to work
Posted: Tue May 19, 2009 7:02 pm
by TheStoryTeller
Darhazer wrote:The difference between exec() / system() and the ` operator is that the functions return only the last line of the output, and if it is a empty string, or if output is piped to /dev/null, you won't receive anything.
` operator, like the passthru function, return the whole output.
If that is so why does the code
return nothing?
Re: exec() command doesn't seem to work
Posted: Wed May 20, 2009 4:27 pm
by Darhazer
Try using passthru and see the results, maybe your server outputs a empty line at the end. On my hosting, both passthru('whoami') and echo exec('whoami') output my username.