[英]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);
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.