小编Mic*_*rns的帖子

PHP Powershell命令

试图在php中运行以下命令来运行powershell命令...

以下作品:

$output = shell_exec(escapeshellcmd('powershell get-service | group-object'));
Run Code Online (Sandbox Code Playgroud)

我无法像这样运行它:

$output = shell_exec('powershell get-service | group-object');
Run Code Online (Sandbox Code Playgroud)

它不会通过管道 字符

但如果我试图运行:

$output = shell_exec(escapeshellcmd('powershell get-service | where-object {$_.status -eq "Running"}'));
Run Code Online (Sandbox Code Playgroud)

我没有输出.

下列:

$cmd = escapeshellcmd('powershell get-service | where-object {$_.status -eq "Running"}');
Run Code Online (Sandbox Code Playgroud)

收益:

powershell get-service ^| where-object ^{^$_.status -eq ^"Running^"^}
Run Code Online (Sandbox Code Playgroud)

有关为什么会发生这种情况以及如何解决此问题的任何建议?

编辑:我也可以将其作为.ps1脚本运行,但我希望能够将$ var传递给它.

php powershell

7
推荐指数
1
解决办法
8769
查看次数

标签 统计

php ×1

powershell ×1