从php执行PowerShell脚本

从php执行PowerShell脚本,php,powershell,Php,Powershell,我想使用php执行PowerShell脚本。使用cmd可以很好地工作,但是使用php不行,我使用的是wamp服务器 我的代码如下: <?php ini_set('max_execution_time', 300); //$output=shell_exec('cd C:\AWS\Distributed-setup-3'); //$output=shell_exec('cd'); $output=shell_exec('powershell.exe -command C:\AWS\Distr

我想使用php执行PowerShell脚本。使用cmd可以很好地工作,但是使用php不行,我使用的是wamp服务器

我的代码如下:

<?php
ini_set('max_execution_time', 300);
//$output=shell_exec('cd C:\AWS\Distributed-setup-3');
//$output=shell_exec('cd');
$output=shell_exec('powershell.exe -command C:\AWS\Distributed-setup-3\AWSExecuter.ps1');
echo $output;
?>

在这里,我使用
Input.yaml
文件获取输入,它在输入文件“Input.yaml”中给出了错误作为问题。但对于手动执行,我使用相同的输入文件。在那里它不会给出任何错误


有人能帮我吗?三天以来我一直在做这个。我正在了解如何调试此文件。

只需将$psDIR更改为您的PowerShell路径(例如%SystemRoot%\system32\WindowsPowerShell\v2.0)


这是我在powershell脚本中调用的python代码的问题,我已经解决了。现在它工作正常

在php中,我使用的是这样的



请提供Input.yaml的内容。我尝试过这一个,它没有给出任何输出或任何错误。我在$psDIR%SYSTEMROOT%\System32\WindowsPowerShell\v1.0中提到过类似的内容。您能像这样更改%SYSTEMROOT%吗
$psDIR=“C:\Windows\System32\WindowsPowerShell\v1.0”这是AWS python代码的问题,我已经解决了。现在它工作正常。在php中,我这样使用过,很高兴听到mate这样说。快乐编码!
<?php
ini_set('max_execution_time', 300);
$psPath = "powershell.exe";
$psDIR = "PathToPowrshell";
$psScript = "C:\AWS\Distributed-setup-3\AWSExecuter.ps1";
$runScript = $psDIR. $psScript;
$runCMD = $psPath." ".$runScript;
$output= shell_exec($runCMD);
echo( '<pre>' );
echo( $output );
echo( '</pre>' );
?>
<?php
        ini_set('max_execution_time', 300);
        $output= shell_exec('powershell -command C:/AWS/Distributed-setup-3/AWSExecuter.ps1');
        echo( '<pre>' );
        echo( $output );
        echo( '</pre>' );          
 ?>