我正在使用exec()
函数来执行相同的外部程序,并且我想在某些情况下停止其中一个程序。但以下命令:
taskkill /IM program.exe
将会杀死所有program.exe
。所以我认为最好的方法是通过 PID 杀死程序进程。
所以,我想到的方法是每次执行程序时获取PID,然后杀死它。
我在 Windows XP 上使用 PHP 5.3。
最佳答案
Windows 上的 exec 会挂起,直到子进程结束。你需要一个 child 的 PID,所以我想你想 nohup 一个 child 。
试试这个代码,它对我有用。它 nohups notepad.exe 并显示其 PID
$command = 'notepad.exe';
$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->exec("notepad.exe");
print_r ( $oExec->ProcessID )
请注意 $WshShell->exec 而不是 $WshShell->run,正如某些 google 资源声称的那样。
愿它能帮助别人
关于php - 在 Windows XP 中是否可以获取由 exec() 启动的进程的 PID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11807556/