User Contributed Notes: exec
landon@bradshaw.org
28-Jul-1999 11:30
<p><i>STDERR</i> is not handled and any output to will be passed to the browser as part of the page.</p>
<p>To stop this from happening you can append '2>&1' on the end of your command-line to redirect STDERR to STDOUT.</p>
dpk@nwserv.com
26-Aug-1999 09:49
Note that for some reason PHP does not pass the environment on to the called programs.
markmadsen@yahoo.com
27-Dec-1999 11:38
PHP 3.0.12 is required for this to work on Windows 2000 (and possibly Winnt 4 but I can't confirm that). PHP 3.0.12 is not available as a binary, you must compile it.
eric@interplas.com
17-Feb-2000 04:01
You may find running /usr/bin programs will not work because the 'nobody' user environment is somewhat skimpy. putenv("HOME=/home/nobody") and putenv("USER=nobody") before the exec() call will help (as long as you've edited /etc/passwd so that 'nobody' can have a place to call home).
bert@box.balpol.tudelft.nl
29-Feb-2000 01:34
After replacing PHP4b3 with PHP4b4pl1, exec("some/unix/command") silently didn't return anything anymore. It turned out that exec() seems to be changed into shell_exec(). At least for me everything worked after replacing exec() with shell_exec().
geek@freemail.it
02-Mar-2000 04:37
i need to print in my php page the output of a script which is http located, i have noticed that exec works just for local scripts..
in this case i have a C script which generate me some html code (banner image and its href) and a php where i have to inert that code here and there...
please help, thanks
tspaeth@netactive.de
10-Mar-2000 04:32
I agree to bert@box.balpol.tudelft.nl with that "exec" stuff.
But "shell_exec" seems undocumented!?!
gysi@cyberlink.ch
11-Mar-2000 05:37
with the upgrade to php 3.0.15 the exec/passthru functions doesn't return <string>.
Example:
<?
$pwd = exec("pwd");
echo $pwd;
?>
will print nothing, so $pwd is empty.
However, when I use system() instead of exec() there is an output from the system()-function itself, but $pwd is also empty this time. The output from the system()-function proves that the command was succsessfuly executed, but the value wasn't submitet to $pwd.
Has anybody else got this misbehavior?
Does anybody have a quick fix for this?
keith@MagicClicks.com
15-Mar-2000 01:08
If PHP is waiting on your *NIX background processes, try this redirecting all output to /dev/null:
<br>
nohup perl mycmd.pl >/dev/null 2>&1 &
<br>
I didn't need the output. If you do...???
pierre-henri@wanadoo.be
21-Mar-2000 09:41
Exec method and release 3.0.15.
As describe before the Exec methods doesn't return any output anymore.
You can get the result of the command using the second parameter on the function wich is an array.
pm@rednet.com.ar
22-Mar-2000 06:55
I need to execute a perl script from inside a php3, how can I do this ?
I have a redir.pl to redirect pages, but I try with the examples here and I can't make it work
What I'm missing ?
Pablo Murillo
zwerschke@urz.uni-heidelberg.de
24-Mar-2000 02:20
exec() does not return the last line of the output in PHP 3.0.15. This is a bug and surely will be fixed in the next release. See also
http://bugs.php.net/bugs.php3?id=3915
j_herlit@informatik.uni-kl.de
28-Mar-2000 09:41
exec("/usr/bin/touch /tmp/testfile");
doesn´t do anything. Neither system() nor passthru() does something. What am I doing wrong ?
giwarden@ucla.edu
01-Apr-2000 04:22
I'm having trouble getting php to fire off a background process and proceed asynchronously without caring about the status of that other process. I got it to *sort of* work by using the above suggesting using nohup or by using a perl script as a wrapper to close the STDIN, STDOUT, and STDERR, and fork the process. The reason it only sort of works is because the rest of the php code on that transaction gets processed, but any further requests with that browser just hang (it's okay if I close netscape and connect again though). Does this have anything to do with sessions? Any ideas for forking asynchronous background processes with php, or do I have to come up with something else to do this?
cregnier@etu.info.unicaen.fr
04-Apr-2000 06:53
I wonder how to create a directory
$ref=shell_exec("mkdir ../aa";);
but it doesn't works.
thanks
james@whispering.org
05-Apr-2000 04:12
Is it possible to pass PHP3 variables as arguments to the system() or exec() command lines? Whenever I try to pass one with something such as system("/bin/blah $var1 $var2"), the PHP preprocessor tells me: "Warning: Cannot pass expression as argument 2 by reference in ..."
ppruett@spacecoast.org
06-Apr-2000 02:06
I wanted to pass a lot of variables from a php shopping cart, MyCart, to the c program that does my credit card processing, www.cardservice.com/linkpt I wonder how to best pass the environment on to the called programs? any thoughts? For example I could have php save to sql database then pass the key to my program which would have to be written to know who to query the the sql server, pain... I could make a big ugly array in put in the back tick...
oh well...
verolix@email.com
24-Apr-2000 07:28
I want to execute 'ipchains' inside
php3 script.. I am quite sure, I have seen sombody does this.. but how?.. it said permission denied all the time?
I am running Apache with php3 as a module
brads@avalon.net
25-Apr-2000 01:44
I have been able to pass $variables in both system and exec but I need to call a program that requires double quotes around the input :
system("/programname "$variable1" $variable2");
So does anyone know what the escape character is for " quotes" within a system() call???
nv@mindimage.net
25-Apr-2000 08:55
brads: try it with
$program = "/program \"" . $var1 . "\" " . "\"" . $var2 . "\"";
system($program);
not sure if it works though
brads@avalon.net
03-May-2000 03:26
I ended up setting a variable $quote='"' thats a double quote and it works so smooth...
compwiz@bigfoot.com
05-May-2000 09:30
Is there any mechanism is there to stop a user from doing exec("/bin/rm /some/file/owned/by/nobody"); ? When I tried such a command, to my surprise, it actually worked.
terry@terrym.com
09-May-2000 05:49
The above "See Also" reference to "EscapeShellCmd" should be linked to:
http://www.php.net/manual/function.escapeshellcmd.php
One other also needs linked.
Terry
olive@deep-ocean.net
10-May-2000 01:35
hello all.
i'm wondering how to execute commands as another user. that is, i protect a page with a login/pass. i get the login/pass ($PHP_AUTH_*), and now, i would like to do:
exec($PHP_AUTH_USER,$PHP_AUTH_PASS,"$myCommand",$output,$return);
i've tried
exec("echo $PASSWD | su $USER -c $command");
but su doesn't accept this behavior.
any help would be appreciated...
nagey@ccweb.com
17-May-2000 05:39
is there a good reason why i cant get the vars $username and $passwd from a form and then do:
exec("/usr/local/bin/htpasswd -b /web/whatever/.htpasswd ".$username." ".$passwd);
it doesnt work with shell or passthru either. why?