2017-03-17 194 views
0

我有一個文件,其中包含一個powershell腳本,必須根據我提交給php表單的值運行。使用php運行powershell腳本

我已經想出瞭如何運行linewise命令。如果我可以將表單值作爲輸入傳遞給shell腳本並獲取輸出,那將是非常好的。

有關如何將表單值發佈到PowerShell的任何想法讀取主機元素?

感謝提前:)

編輯:如果有人可以請讓我知道一種方法來應對讀主機通過PHP,這也將是巨大的:)

+0

你能提供一些你迄今爲止嘗試過的例子嗎? –

+0

我不知道如何將值輸入到讀取主機從 – Sandushi

回答

1

在此我不會用Read-Host因爲它只對需要提示用戶手動輸入值的交互式腳本非常有用。

正如你想從PHP調用腳本,使用參數會更好。這樣,您可以從命令行向腳本提供輸入。

更新此示例腳本使用參數...

$computerName = Read-Host -Prompt "Enter your Computer Name" 
$filePath = Read-Host -Prompt "Enter the File Path" 

Write-Host "$computerName is your computer name!" 
Write-Host "Your files are in $filePath location" 

當運行

PS C:\> Get-Something.ps1 

Enter your Computer Name: SERVER1 
Enter the File Path: C:\folder 
SERVER1 is your computer name! 
Your files are in C:\folder location 

你可以使用參數這樣這樣會生成以下的輸出:

Param(
    [string]$computerName, 
    [string]$filePath 
) 

Write-Host "$computerName is your computer name!" 
Write-Host "Your files are in $filePath location" 

運行時會產生以下輸出

PS C:\> Get-Something.ps1 –computerName SERVER1 –filePath C:\folder 

SERVER1 is your computer name! 
Your files are in C:\folder location 
+0

謝謝加載。是否還有一種方法可以用來將輸出的特定部分分配給一個php變量? – Sandushi

+0

@Sandushi最好問一個新的問題,因爲這是一個不同的主題。 –

+0

可以請你檢查這個鏈接http://stackoverflow.com/questions/42918185/how-do-i-assign-variables-from-powershell-script-to-php? – Sandushi