Partner and Community Forums
Why I can't exec batch file? ???
Last post Apr 27, 2013 11:29 PM by calmchessplayerfunguy
May 06, 2008 03:38 AM|toeh101|LINK
I've tried to use PHP exec() to execute DOS command.
It works with command exec("md example_dir") .
But when I put test.bat in same directory and run PHP with exec("test.bat") , it doesn't work. No error showed but not work.
Anyone can help me?
May 06, 2008 02:29 PM|brashquido|LINK
You'll need to specify that you wish to use the Windows command line to execute your batch file. Have you tried something like exec("cmd.exe /c test.bat") ?
May 06, 2008 04:32 PM|anilr|LINK
Also, the current working directory of the php process (in the fastcgi case) is not the application/vdir root, but the directory from where php is run, so use a fully qualified path.
Aug 22, 2008 10:46 AM|luxus|LINK
I think that this is not correct.
PHP uses cmd.exe /c to execute the value passed to exec. I've the same problem and I am sure that the cwd of my script is used.
- start_test.bat is my batch i want to execute
- My PHP-script and the start_test.bat are located in C:\Inetpub\wwwroot\test
When call "type start_test.bat" (PHP executes "cmd.exe /c type start_test.bat") by this PHP code:
$a = array();
exec("type start_test.bat", $a);
I get the lines of start_test.bat
When I call "start_test.bat" (PHP executes "cmd.exe /c start_test.bat") the result is NULL.
How can I get batch files working?
Aug 22, 2008 11:26 AM|luxus|LINK
i read the cmd /c thing over. This is working.
You can run batch files by calling "cmd /c yourbatch.bat" so PHP will exec "cmd /c cmd /c yourbatch.bat".
But why is this nessecary? On PHP/Apache on W32 calling batch files works without the double cmd /c?
Apr 17, 2010 04:09 PM|bradbaumann|LINK
I was running Apache/PHP on Win2k3, then upgraded recently to IIS 7 on Win2k8 -- never needed the "cmd /c" before, but adding it worked!
Thanks for the solution!
Apr 27, 2013 11:29 PM|calmchessplayerfunguy|LINK
on my windows machine 8 machine running IIS 8 I can run the batch file just by putting the bats name and forgettig the path to it. Or by putting the bat in c:\windows\system32 don't ask me how it works but it does. LOL
$test=shell_exec("C:\windows\system32\cmd.exe /c $streamnumX.bat");