开发者

Running a Powershell Script from PHP

开发者 https://www.devze.com 2023-03-31 10:21 出处:网络
The following I can run in the command Prompt with no problem: powershell -noexit \"& \"\"C:\\wamp\\www\\mypowersher.ps1”\"\"

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>' );
0

精彩评论

暂无评论...
验证码 换一张
取 消