2017-06-22 120 views
0

我想通過PHP執行powershell腳本,並希望在PHP變量中返回參數。所以爲了測試,我試圖從powershell腳本獲取windows版本。PHP:echo從powershell腳本返回參數

<?php 

exec("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe gwmi  win32_operatingsystem | % caption",$output); 

echo('<pre>'); 
var_dump($output); 
echo('</pre>'); 

?> 

輸出:

C:\wamp64\www\py\indexPHP.php:6: 
array (size=0) 
    empty 

但它返回一個空數組。

回答

0

您的電話不正確。

exec("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -Command (GWMI Win32_OperatingSystem).Caption", $Output); 
+0

仍然沒有工作:( – SDA

+0

@SDA我不知道PHP,但看着的文件,它會出現,你需要對你噴涌到陣列的參考。因此,例如,聲明在exec()之前使用'$ Output',然後使用'&$ Output' – TheIncorrigible1

+0

它不起作用,我認爲可能存在安全問題,運行exec命令......因爲簡單的代碼不工作並且沒有記錄錯誤 – SDA