使用php运行powershell脚本
问题描述:
我有一个文件,其中包含一个powershell脚本,必须根据我提交给php表单的值运行。使用php运行powershell脚本
我已经想出了如何运行linewise命令。如果我可以将表单值作为输入传递给shell脚本并获取输出,那将是非常好的。
有关如何将表单值发布到PowerShell的任何想法读取主机元素?
感谢提前:)
编辑:如果有人可以请让我知道一种方法来应对读主机通过PHP,这也将是巨大的:)
答
在此我不会用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
你能提供一些你迄今为止尝试过的例子吗? –
我不知道如何将值输入到读取主机从 – Sandushi