2016-04-20 147 views
1

嘗試從php運行示例批處理文件以關閉Firefox瀏覽器。但它並沒有關閉瀏覽器。手動如果從命令提示符執行批處理文件正在工作。批處理文件未從php執行

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'); 

回答

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,而不是反引號操作符。