繁体   English   中英

无法从php运行powershell脚本

[英]Can't run powershell script from php

我使用以下Powershell脚本来获取在cisco设备上show runshow 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评论的那样,问题是我的网络服务器无法到达目标目录。

通过正确地对路径进行硬编码,问题得到了解决。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM