试图在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传递给它.