Jump to content

shell_exec hangs page...


andrewdav

Recommended Posts

Hello all,

 

I am using a shell_exec command like the one below:

 

$output = shell_exec('c:\powershell\powershell.exe get-service');
echo($output);

 

However, when launching the page, the browser will hang with the hour-glass. If i end the powershell.exe process on the web server via task manager, the browser then returns the expected output.

 

Any idea why this is? Other commands, like ipconfig return the correct output and the browser displays "Done" in the bottom left.

 

Any help appreciated.

 

Andrew

 

Link to comment
Share on other sites

Have you tried running the command via the cmd.exe interface? Does it work properly there or does it hang as well?

 

Chances are it is expecting more input or "pause's" after it executes which is why it would hang.

Link to comment
Share on other sites

the same thing happens with this command

 

$output = shell_exec("cmd");

 

i'd expect to see

 

Microsoft Windows XP [Version 5.1.2600]

© Copyright 1985-2001 Microsoft Corp.

 

C:\>

 

return to $output - but this doesn't happen, just hangs the browser.

Link to comment
Share on other sites

The reason it hangs is it is expecting input, without the exit command being issued the command prompt is just going to sit there waiting for input, as that is what it does.

 

So if you were able to pass "exit" to that command prompt, it would un-hang the browser as it would kill the cmd process. Does that make sense?

Link to comment
Share on other sites

  • 4 months later...

I'm experiencing this same problem too, andrewdav, did you ever solve this?

 

My code:

$output = array();
exec("powershell get-service", $output);
exec("exit");
print_r($output);

 

 

My browser hangs until I goto Task Manager on the machine and kill Powershell.exe, then my results are returned.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.