Reputation: 61
I am trying to run a simple PHP that runs a powershell script, if I use this code I get the results in a command window, but I get an empty array in the browser:
<?php
exec("powershell C:\\Inetpub\\wwwroot\\my_shell.ps1 < NUL", $output);
echo "<pre>";
print_r($output);
echo "</pre>";
?>
I believe the NUL will discard the output, however it works in the browser found it on [this Fourm][1]
If I use this code, without the NUL I will get the results on a command window but if I run the script in the browser will keep loading forever and it will never give me any results:
exec("powershell C:\\Inetpub\\wwwroot\\emsrDev\\manual_shell.ps1", $output);
Same results if I do it this way:
$output = shell_exec("powershell C:\\Inetpub\\wwwroot\\emsrDev\\manual_shell.ps1");
The powershell Script runs fine if I ran it independently:
$cmd = "cmd.exe";
&$cmd "/C echo update tasks set last='manual' where id='8'; | sqlplus vvv/www@xxx";
So I need to execute this in a browser and get the output.
Upvotes: 5
Views: 1029
Reputation: 828
The powershell process isn't terminating, which causes the browser to hang. Add the following to the end of your script
Stop-Process -processname powershell*
Upvotes: 1