I have this problem: On a ISS web server, windows 7 x64 professional, zend server installed. Running this command under php:
exec('dir',$output, $err);
$output is empty, $err=1.
So exec is not returing the output, it seems has some errors.
Php disable_functions
is empty, php is not on safe mode, is standard, I check all option.
It seems to be a general errors, even search on google do not give results.
Please write every one his experince and eventual solutions or workarounds.
The exec() function is an inbuilt function in PHP which is used to execute an external program and returns the last line of the output. It also returns NULL if no command run properly. Syntax: string exec( $command, $output, $return_var )
php phpinfo(); ?> You can search for disable_functions and if exec is listed it means it is disabled. To enable it just remove the exec from the line and then you need to restart Apache and you will be good to go. If exec is not listed in the disable_functions line it means that it is enabled.
The shell_exec() function is an inbuilt function in PHP that is used to execute the commands via shell and return the complete output as a string. The exec() function is an inbuilt function in PHP that is used to execute an external program and returns the last line of the output.
There are a few posts to the relevant sections of the PHP Manual such as this one:
I was having trouble using the PHP exec command to execute any batch file. Executing other commands (i.e., "dir") works fine). But if I executed a batch file, I receieved no output from the exec command.
The server setup I have consists of Windows Server 2003 server running IIS6 and PHP 5.2.3. On this server, I have:
- Granted execute permissions to the Internet User on c:\windows\system32\cmd.exe.
- Granted Everyone->Full Control to the directory in which the batch file is written.
- Granted Everyone->Full Control on the entire c:\cygwin\bin directory and its contents.
- Granted the Internet User "log on as batch" permissions.
- Specified the full path to each file being executed.
- Tested these scripts running from the command line on the server and they work just fine.
- Ensured that %systemroot%\system32 is in the system path.
It turns out that even with all of the above in place on the server, I had to specify the full path to cmd.exe in the exec call.
When I used the call:
$output = exec("c:\\windows\\system32\\cmd.exe
/c $batchFileToRun");
then everything worked fine. In my situation,
$batchFileToRun
was the actual system path to the batch file (i.e., the result of a call to realpath()).
There are a few more on both the exec
and shell_exec
manual pages. Perhaps following through them will get it up and working for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With