简体   繁体   English

从PHP运行Powershell脚本

[英]Running a Powershell Script from PHP

The following I can run in the command Prompt with no problem: 以下我可以在命令提示符下运行而没有问题:

powershell -noexit "& ""C:\wamp\www\mypowersher.ps1”""

But I want to add it to my PHP script. 但我想将其添加到我的PHP脚本中。 Is it possible? 可能吗? I tried using exec but it did not work. 我尝试使用exec但是没有用。

    $psPath ='"C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"';
    $psDIR = 'C:\\wamp\\www\\mypowersher.ps1';  
    $psScript = 'mypowersher.ps1';
    $runScript = $psDIR. $psScript;
    $runCMD = $psPath." "& ".$runScript." 2>&1"";   

exec( $runCMD);

I think it's possibly a problem with configuration since your description is unclear. 我认为这可能是配置问题,因为您的描述不清楚。 So try turning safe_mode= on on your WAMP server. 因此,请尝试在WAMP服务器上打开safe_mode= on

Additionally you can try system() if it makes any differences. 另外,如果有任何区别,可以尝试使用system()

Try it this way

$psPath = '"C:\\Windows\\System32\WindowsPowerShell\v1.0\\powershell.exe"';
$psDIR = "C:\\wamp\\www\\";
$psScript = "mypower.ps1";
$runScript = $psDIR. $psScript;
$runCMD = $psPath." ".$runScript." 2>&1";

exec( $runCMD,$out,$ret);


$output= shell_exec($runCMD); 
echo( '<pre>' );
echo( $output );
echo( '</pre>' );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM