【问题标题】:Browser Hangs Executing PHP that runs a Powershell浏览器挂起执行运行 Powershell 的 PHP
【发布时间】:2012-05-09 19:56:34
【问题描述】:

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

<?php 
exec("powershell C:\\Inetpub\\wwwroot\\my_shell.ps1 < NUL", $output);

echo "<pre>";
print_r($output);
echo "</pre>";
?>

我相信 NUL 会丢弃输出,但是它可以在 [this Fourm][1] 上找到的浏览器中工作

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

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 命令正在运行的代码。
  • stackoverflow.com/a/5319219/763026 -- 看这里。 Microsoft 建议运行 Set-ExecutionPolicy RemoteSigned -Scope LocalMachine。这允许计算机上的所有用户帐户毫无问题地运行本地脚本,但需要确认才能运行从 Internet 下载的脚本。
  • @SeeSharp 执行策略运行良好,我可以直接从powershell运行脚本,谢谢。

标签: php powershell exec shell-exec


【解决方案1】:

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

Stop-Process -processname powershell*

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-07
    • 2012-12-20
    • 2019-03-25
    相关资源
    最近更新 更多