尝试从php运行示例批处理文件以关闭firefox浏览器。但它不会关闭浏览器。如果从命令提示符下手动执行批处理文件,则它正在工作。
关闭浏览器.bat
tskill firefox
关闭.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');
作为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
而不是backtick运算符。