5

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.

OmarL
  • 61
  • 4
  • Insufficient information. Please post the code that the `powershell` command is running. –  May 09 '12 at 20:03
  • http://stackoverflow.com/a/5319219/763026 -- look here. Microsoft recommends running Set-ExecutionPolicy RemoteSigned -Scope LocalMachine. This allows all user accounts on a machine to run local scripts without issue, but requires confirmation to run scripts downloaded from the internet. – Angshuman Agarwal May 09 '12 at 20:04
  • @SeeSharp The execution Policy works fine, I can run the script directly from powershell, Thanks. – OmarL May 09 '12 at 21:30

1 Answers1

1

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*
mitchimus
  • 830
  • 1
  • 10
  • 24