浏览器挂起 执行运行 Powershell 的 PHP


Browser Hangs Executing PHP that runs a Powershell

我正在尝试运行一个简单的PHP,它运行一个Powershell脚本,如果我使用此代码,我会在命令窗口中获得结果,但在浏览器中得到一个空数组:

<?php 
exec("powershell C:''Inetpub''wwwroot''my_shell.ps1 < NUL", $output);
echo "<pre>";
print_r($output);
echo "</pre>";
?>

我相信 NUL 会丢弃输出,但它在浏览器中工作 在 [这个 Fourm] 上找到它[1]

如果我使用此代码,如果没有 NULL,我将在命令窗口中获得结果,但如果我在浏览器中运行脚本将永远保持加载,并且永远不会给我任何结果:

exec("powershell C:''Inetpub''wwwroot''emsrDev''manual_shell.ps1", $output);

如果我这样做,结果相同:

$output = shell_exec("powershell C:''Inetpub''wwwroot''emsrDev''manual_shell.ps1");

如果我独立运行它,Powershell 脚本运行良好:

$cmd = "cmd.exe";
&$cmd "/C echo update tasks set last='manual' where id='8'; | sqlplus vvv/www@xxx";

所以我需要在浏览器中执行它并获取输出。

powershell 进程未终止,这会导致浏览器挂起。将以下内容添加到脚本末尾

Stop-Process -processname powershell*