Jump to content

Correct way to execute .bat files?


JasonO

Recommended Posts

Hi,

 

I have a bat file that I would like to run when a button is pressed on my page.

 

I have tried using exec and shell_exec, both with no luck. The page just continues to load and anything after the line where the file is executed on my PHP page is not loaded.

Also, nothing happens on the server when looking at it remotly apart from making cmd.exe start hidden in the background.

 

The bat files are in the root of the C: Drive, and when launched on the server locally they work fine.

 

Can anyone give me an example or hints to getting a batch file to execute via PHP please?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/37602-correct-way-to-execute-bat-files/
Share on other sites

Hello JasonO,

I have used the XShell php class to launch programs via the windows command line. It can be found by doing a seach for XShell at phpclasses.org . Be sure to test the command in in Start > Run > cmd window first, and make sure any quotes are escaped when using it in your the script.

 

Good luck on your project.

OK These are what I have tried.

file.bat is available in the root of the C: drive and the same folder as the php file when using these commands.

 

exec ("file.bat");

 

exec ("C:\\file.bat");

 

exec ("psexec C:\\file.bat");

 

exec ("psexec file.bat");

 

$command = shell_exec ("file.bat");
echo $command ;

 

$command = shell_exec ("C:\\file.bat");
echo $command ;

 

$command = shell_exec ("psexec file.bat");
echo $command ;

 

$command = shell_exec ("psexec C:\\file.bat");
echo $command ;

 

I do have the PS tools from Microsoft installed on the server and they work when run in CMD, so psexec works.. but the page just keeps loading when executed.

 

Edit : Thanks for the advice ultrus, I will have a go at using it now.

 

Edit II : OK I have the php file from phpclasses, although there was no readme or instructions on how to use this. What do I do with it?

Archived

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

×
×
  • 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.