slowfib Posted August 19, 2010 Share Posted August 19, 2010 I'm using PHP on a windows box to execute some powershell scripts, my only problem is that the browser hangs on the request. The browser will continue to hang until I goto Task Manager and kill Powershell.exe, then my results are returned as expected. I've tried to execute an "exit" command after executing my Powershell commands, but that doesn't seem to work. Anyone used Powershell before, or have any ideas on how I could handle this otherwise? Here's my code: $output = array(); exec("powershell get-service", $output); print_r($output); Thank you! Quote Link to comment Share on other sites More sharing options...
nadeem Posted August 19, 2010 Share Posted August 19, 2010 try to put it in a batch file.bat and then execute that Quote Link to comment Share on other sites More sharing options...
slowfib Posted August 19, 2010 Author Share Posted August 19, 2010 Hmmmm... executing the batch file still hangs the browser and Powershell keeps on running in the background. But if I execute the batch file inside of windows, Powershell.exe stops running as soon as the batch file is done executing. I'm wondering if I can pipe an exit in Powershell to exit once it's finished or something... Here's my code now: $output = array(); $filename = "C:\\temp\\powershell.bat"; $handle = fopen($filename, "w"); fwrite($handle, "powershell.exe get-service > C:\\Temp\\powershell-output.txt\nexit"); fclose($handle); exec("C:\\temp\\powershell.bat"); unlink($filename); $filename = "C:\\Temp\\powershell-output.txt"; $handle = fopen($filename, "r"); $contents = fread($handle, filesize($filename)); fclose($handle); unlink($filename); print_r($contents); Quote Link to comment Share on other sites More sharing options...
slowfib Posted August 19, 2010 Author Share Posted August 19, 2010 FINALLY figured it out with the help of Google Needed to add in a < NUL to the powershell command. $output = array(); exec("powershell get-service < NUL", $output); print_r($output); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.