JasonO Posted February 8, 2007 Share Posted February 8, 2007 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 More sharing options...
trq Posted February 8, 2007 Share Posted February 8, 2007 I have tried using exec and shell_exec, both with no luck. Post your code. Link to comment https://forums.phpfreaks.com/topic/37602-correct-way-to-execute-bat-files/#findComment-179799 Share on other sites More sharing options...
ultrus Posted February 8, 2007 Share Posted February 8, 2007 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. Link to comment https://forums.phpfreaks.com/topic/37602-correct-way-to-execute-bat-files/#findComment-179803 Share on other sites More sharing options...
JasonO Posted February 8, 2007 Author Share Posted February 8, 2007 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? Link to comment https://forums.phpfreaks.com/topic/37602-correct-way-to-execute-bat-files/#findComment-179805 Share on other sites More sharing options...
JasonO Posted February 8, 2007 Author Share Posted February 8, 2007 Still no luck with XShell Class. I'm totally stumped in to what I do with it. Link to comment https://forums.phpfreaks.com/topic/37602-correct-way-to-execute-bat-files/#findComment-179848 Share on other sites More sharing options...
ultrus Posted February 8, 2007 Share Posted February 8, 2007 Hey, I had to get on my home machine that was sitting at work. Here is an exapmle: <?php include_once "XShell.php"; $edit = new XShell; $command = "\"C:\\Program Files\\theProgram\\theProgram.exe\""; $edit->Execute($command); $edit = null; unset($edit); ?> Link to comment https://forums.phpfreaks.com/topic/37602-correct-way-to-execute-bat-files/#findComment-179909 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.