可以';t从php运行powershell脚本


Can't run powershell script from php

我使用以下Powershell脚本在cisco设备上运行show run命令:

getconfig.ps1

$ErrorActionPreference ="Inquire"
Import-Module SSH-Sessions
$time ="$(get-date -f yyyy-MM-dd)"
$filename ="config"
$ext =".txt"
$filepath ="temp'"
$d1 ="x.x.x.x"
$u1 ="user"
$p1 ="password"
New-SshSession $d1 -Username $u1 -Password "$p1"
$c1 ="show run"
$Results = Invoke-Sshcommand -InvokeOnAll -Command "$c1" | Out-File "$filepath$filename-$time$ext"
Remove-SshSession -RemoveAll
exit

当我通过右键单击/使用powershell运行手动运行此脚本时,这很好。当我尝试通过PHP运行这个脚本时,问题就出现了。

index.php

<?php
$output = shell_exec('powershell C:'wamp'www'getconf'script'getconfig.ps1');
echo "<pre>$output</pre>";
?>

index.php永远加载,从不给我输出,也从不创建结果文件。

我试着运行另一个脚本,比如test.ps1,它只需创建一个目录,就可以正常工作;我得到了输出,我的目录就创建了。

我的powershell脚本有效。

PHP和我的PowerShell脚本之间的链接是有效的。

我不明白问题出在哪里。

正如jisaak所评论的,问题是我的Web服务器无法访问目标目录。

通过正确地对路径进行硬编码,问题已经解决。