note 105509 added to function.shell-exec
| From: | aaron_mckinstry at yahoo dot com | Date: | Tue, 23 Aug 2011 19:29:20 +0000 |
| Subject: | note 105509 added to function.shell-exec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-182679@lists.php.net to get a copy of this message | ||
Interestingly, if you execute a script which is not in your path (or you have made a typo, or if the
script does no exist at all), you will get no return value. The error will be logged into the
error_log of your webserver.
If you don't want to pass parameters to the program you need to run, you can manually create a
link to the program, and then place the link inside the directory where you're running your php
script from. Then just use
shell_exec('executable_program.exe.lnk');
to run it. This will work if you don't want to pass command line parameters to your executable.
If you want to pass command line parameters to the program, then you can do two things that I know
of:
1)Download one of many command line tools that allow you to create and modify shortcuts, and then
use the tool to change the target property of the shortcut to include the command line parameters
you want to pass (or you can use a vbscript to do this, possibly using php's file capabilities
to change the parameters on the fly within the vbscript; then you could run the vbscript from the
command line to create the shortcut and run the shortcut as shown above).
2)The other workaround is to use PHP file's capabilities to write a temporary batch file that
contains the command line call you want to perform (i.e., the program you want to run that is
outside the current path) and then execute the batch file from the shell_exec()/exec() function.
E.g.:
$handle = fopen(getcwd().'\\temp_bat_file.bat', 'w');
fwrite($handle, "$command");
fclose($handle);
shell_exec("temp_bat_file.bat");//or exec("temp_bat_file.bat");
NOTE: In $command, I think you have to list the absolute path to the executable/program you want to
run (i.e., "C:\absolute\that\to\dir\executable.exe").
----
Server IP: 64.71.164.2
Probable Submitter: 2001:480:10:160:213:72ff:fe1f:5321
----
Manual Page -- http://www.php.net/manual/en/function.shell-exec.php
Edit -- https://master.php.net/note/edit/105509
Del: integrated -- https://master.php.net/note/delete/105509/integrated
Del: useless -- https://master.php.net/note/delete/105509/useless
Del: bad code -- https://master.php.net/note/delete/105509/bad+code
Del: spam -- https://master.php.net/note/delete/105509/spam
Del: non-english -- https://master.php.net/note/delete/105509/non-english
Del: in docs -- https://master.php.net/note/delete/105509/in+docs
Del: other reasons-- https://master.php.net/note/delete/105509
Reject -- https://master.php.net/note/reject/105509
Search -- https://master.php.net/manage/user-notes.php