MetalSmith Posted February 20, 2009 Share Posted February 20, 2009 Hello all! I am still having issues with this command. How come if I run a basic script such as: <?php exec(regedit); ?> Using php script.php in DOS this script will open the regedit window. If I access the script through my web server the page just crashes. I will not be doing anything with this script it's just something to understand what's happening. My real script will open a session to Linux using Putty and running a command then close. How can I open and run an external program like a regedit in the background do what it needs to and close out without interrupting anything else within the script. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/146107-need-more-help-with-exec/ Share on other sites More sharing options...
JonnoTheDev Posted February 20, 2009 Share Posted February 20, 2009 Permissions! The webserver will run as a non-administrative user i.e. apache For programs to run via the CLI through exec the webserver user must have the permissions available. Quote Link to comment https://forums.phpfreaks.com/topic/146107-need-more-help-with-exec/#findComment-767179 Share on other sites More sharing options...
MetalSmith Posted February 20, 2009 Author Share Posted February 20, 2009 These are permission's set within the Apache httpd.conf? or are these windows security permission's? Quote Link to comment https://forums.phpfreaks.com/topic/146107-need-more-help-with-exec/#findComment-767275 Share on other sites More sharing options...
premiso Posted February 20, 2009 Share Posted February 20, 2009 These are permission's set within the Apache httpd.conf? or are these windows security permission's? I never thought windows had permissions, but you are not putting quotes around what you are executing, this may or may not be the problem but you should quote strings, as that can be taken as a constant. This "should" work in a windows environment, unless apache has been set without having execute access to regedit (which may be as that is an operating system deal that could allow someone to mess up your system.) A better test, in my opinion, is to try and open "notepad.exe" as that should be allowed by all users. Quote Link to comment https://forums.phpfreaks.com/topic/146107-need-more-help-with-exec/#findComment-767282 Share on other sites More sharing options...
MetalSmith Posted February 20, 2009 Author Share Posted February 20, 2009 Well I tried this: <?php exec("notepad.exe"); ?> and my browser just hangs there loading. Is there mode code needed to see the progrma open? Would the note pad open on the client PC or would it open on the web server? Quote Link to comment https://forums.phpfreaks.com/topic/146107-need-more-help-with-exec/#findComment-767333 Share on other sites More sharing options...
premiso Posted February 20, 2009 Share Posted February 20, 2009 Are you doing this on your local server? Or a remote server? Opening an application like that creates a process that essentially will not die. Thus it hangs. This will not open anything on the client PC, it does it on the webserver. In order to access programs on a clients PC you need to have them install ActiveX controls for you to do that. What you are wanting is not possible with php (thank god) without the user downloading/installing software to allow that. Quote Link to comment https://forums.phpfreaks.com/topic/146107-need-more-help-with-exec/#findComment-767338 Share on other sites More sharing options...
MetalSmith Posted February 20, 2009 Author Share Posted February 20, 2009 Well what I am trying to do is from a client PC access a script on a local web server (same network) that will run a php script to open up putty.exe to connect to a Linux box login and run a command then close out putty. Works great if I use the DOS method but takes a user interaction. When its done from the client PC the browser will hang. Can't the script open on he server run its command then close out without hanging up the clients PC? Quote Link to comment https://forums.phpfreaks.com/topic/146107-need-more-help-with-exec/#findComment-767353 Share on other sites More sharing options...
premiso Posted February 20, 2009 Share Posted February 20, 2009 I am not sure of putty's command lines, but I believe you would have to issue an exit command to kill the process. Exec is setup to just run a program. shell_exec is setup to return output after script has run, so that is probably more of what you are looking for. If not play around with the different ways you can do it listed in the exec manual. Quote Link to comment https://forums.phpfreaks.com/topic/146107-need-more-help-with-exec/#findComment-767355 Share on other sites More sharing options...
MetalSmith Posted February 21, 2009 Author Share Posted February 21, 2009 Great! Well thanks for all the help!!! I appreciate it alot! Quote Link to comment https://forums.phpfreaks.com/topic/146107-need-more-help-with-exec/#findComment-767543 Share on other sites More sharing options...
MetalSmith Posted February 21, 2009 Author Share Posted February 21, 2009 Well I did some research and found this chunk of code that said would run a php script in the background. <?php $WshShell = new COM("WScript.Shell"); $oExec = $WshShell->Run('"c:\program files\putty.exe", 7, false'); ?> This one again works under DOS as my other methods did but this time when I connect to it on my PC which has windows XP and Apache the page does not hang which is good! but again it will not run the command to open the file putty.exe. There are no errors either. I am losing ideas. I even tried making the script point to a batch file that ran the program but again DOS fine Web Server no action. Quote Link to comment https://forums.phpfreaks.com/topic/146107-need-more-help-with-exec/#findComment-767582 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.