2017-06-22 47 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

相关问题