簡體   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