note 105509 deleted from function.shell-exec by danbrown
| From: | danbrown@php.net | Date: | Tue, 23 Aug 2011 19:32:58 +0000 |
| Subject: | note 105509 deleted from function.shell-exec by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-182680@lists.php.net to get a copy of this message | ||
Note Submitter: aaron_mckinstry at yahoo dot com
----
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").