Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/146107-need-more-help-with-exec/
Share on other sites

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.

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.

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?

 

 

 

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.

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.

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.