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! Link to comment https://forums.phpfreaks.com/topic/211188-php-and-powershell/ 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 Link to comment https://forums.phpfreaks.com/topic/211188-php-and-powershell/#findComment-1101258 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); Link to comment https://forums.phpfreaks.com/topic/211188-php-and-powershell/#findComment-1101327 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); Link to comment https://forums.phpfreaks.com/topic/211188-php-and-powershell/#findComment-1101339 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.