1
我一直在扼殺我的大腦和我的電腦,希望有人能幫助我。使用參數執行PHP中的powershell腳本
我有一個PHP網站,需要執行一個PowerShell腳本,然後執行和執行。
調用的.ps1的PHP是
define('updaterPath','C:\\artemis\\DbUpdateUtility1.0.12.2');
define('outputLocation',updaterPath.'\\Output');
$CMD = updaterPath . '\\ArtemisXmlUtil.exe';
$action = 'import';
$args= ' -f' . outputLocation;
$psScriptPath = '.\\get-process.ps1';
$query = shell_exec("powershell -command $psScriptPath -cmd '$CMD' -action '$action' -paras '$args' < NUL");
我的.ps1腳本是:
param(
[string]$CMD,
[string]$action,
[string]$paras
)
& $CMD $action $paras
現在,當我回顯完整的命令,它看起來完美的,可以複製和粘貼到PowerShell併成功運行,但是當我嘗試從PHP實際執行它時,它只運行$ CMD變量並忽略$ action和$ paras。
我試圖concactenating變量全部爲1個字符串,但失敗,因爲甚至不能夠看到可執行文件。
完整的命令shouls樣子:
C:\artemis\DbUpdateUtility1.0.12.2\ArtemisXmlUtil.exe import -fC:\artemis\DbUpdateUtility1.0.12.2\Output