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.

3
  • Insufficient information. Please post the code that the powershell command is running. Commented May 9, 2012 at 20:03
  • 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. Commented May 9, 2012 at 20:04
  • @SeeSharp The execution Policy works fine, I can run the script directly from powershell, Thanks. Commented May 9, 2012 at 21:30

1 Answer 1

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*
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.