批处理文件没有从php执行

时间:2016-04-20 11:12:29

标签: php batch-file wamp

尝试从php运行示例批处理文件以关闭firefox浏览器。但它并没有关闭浏览器。手动如果从命令提示符执行批处理文件它正在工作。

closebrowsers.bat

tskill firefox

close.php

<?php

exec('cmd /c C:\wamp\www\fedex\closebrowsers.bat');

print "done";
?>

尝试绝对路径,没有绝对路径,逃避反斜杠。

exec('cmd /c C:\\wamp\\www\\fedex\\closebrowsers.bat');

exec('cmd /c closebrowsers.bat');

1 个答案:

答案 0 :(得分:0)

作为tskill的替代方案,您可以使用taskkill

<?php

print `C:\\Windows\\system32\\taskkill.exe /F /IM chrome.exe /T`;
// or event without the full path to the executable
// print `taskkill.exe /F /IM chrome.exe /T`;
// and even without the full executable name
// print `taskkill /F /IM chrome.exe /T`;

将输出

的内容
SUCCESS: The process with PID 16972 (child process of PID 17912) has been terminated.
SUCCESS: The process with PID 10200 (child process of PID 17912) has been terminated.
.... 
SUCCESS: The process with PID 16764 (child process of PID 17912) has been terminated.
SUCCESS: The process with PID 17912 (child process of PID 2760) has been terminated.

无需单独的批处理文件 / F - 强制终止流程
/ IM - 传递图片名称,例如。的chrome.exe
/ T - 也会杀死子进程

您可以使用exec代替反引号操作符。