Jump to content

How To Use A Web Interface To Execute A Batch Script At Host?


NickBomb

Recommended Posts

First of all; I'm not sure this is in the right section. Please feel free to move it if you deem that necessary.I'd like to know, as topic title states, if there is any way to use a web interface to execute a batch script on the host machine, which will be my home computer?I haven't got any particular server software installed at the moment, so if there is a particular one I need there's no problem.Is there any way to achieve this at all? To make the host machine preform actions simply by using a web interface? I'm not talking about VPN services like LogMeIn or anything like that, just pure HTML with an input button.Thanks in advance!NickBomb

Link to comment
Share on other sites

You can use a server-side language to execute shell commands. For example, in PHP you could use exec().

Link to comment
Share on other sites

I have experienced some issues concerning this.Now, when I try to visit the file with the script in it (commands.php) via the web browser, it simply won't finish loading.It just keeps on spinning, without displaying any output at all, and chrome says "Loading...".When I change the command to be executed to an invalid one (random letters), the page loads just fine. Does anyone have an idea what my problem might be?

Link to comment
Share on other sites

Your batch file has to end before the script will continue (because it is designed to return the stdout of the command). From the manual:

Note: If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.
As per the comments, using Sysinternal's psexec program can also help.
Link to comment
Share on other sites

I don't think my batch file is even started, since the command prompt never pops up. I tried adding 'exit' to the end of the batch file (after the line with "start C:\Progra~1\uTorrent\uTorrent.exe"), but it didn't work. I had planned on using PsTools, but first I have to get this working.I don't care about the output - is there any function that does not wait for the output and just runs the file? (I have tried system(), passthru() among others as well, all of them results in this error)Maybe my php configuration is incorrect? Is there any setting which could cause this problem? (I have tried with register_globals both on and off)

Link to comment
Share on other sites

You may not see the command prompt or any other window pop up, because it doesn't run the program as you. Your problem is that after starting C:\Progra~1\uTorrent\uTorrent.exe, the batch file will wait until uTorrent.exe closes again before ending, and therefore the PHP script will wait, and hang. The solution is to fork the process so the PHP script can continue while uTorrent runs, using psexec or another way.

Link to comment
Share on other sites

I'm sorry, but I still can't get it to work.My code:$command = "psexec -d -i C:\a.bat";passthru($command);When I run that command in the command prompt, a.bat is opened without error. Now, when I visit the webpage where this script is located, it finishes loading and everything, it just doesn't start a.bat. I have checked, and neither psexec.exe nor cmd.exe is running after I run this script. I have tried countless variations; system(), exec(), and also all the different combinations for psexec (\\127.0.0.1, -s, -u username, -p password, among others).

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...