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. Is it possible?
I tried using exec
but it did not work.
$psPath ='"C:\\WINDOWS\\system32\\Windows开发者_JS百科PowerShell\\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.
Additionally you can try system() if it makes any differences.
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>' );
精彩评论