wmeredith Posted July 16, 2013 Share Posted July 16, 2013 Hey guys need help with running a windows bat file from php. Thanks! Quote Link to comment Share on other sites More sharing options...
requinix Posted July 16, 2013 Share Posted July 16, 2013 What have you tried? Quote Link to comment Share on other sites More sharing options...
wmeredith Posted July 16, 2013 Author Share Posted July 16, 2013 $cmd = 'c:\test.bat'; exec($cmd); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $cmd=("c:\test.bat") function execInBackground($cmd) { if (substr(php_uname(), 0, 7) == "Windows"){ pclose(popen("start /B ". $cmd, "r")); } else { exec($cmd . " > /dev/null &"); } } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ exec('C:\Windows\System32\cmd.exe' /c START 'C:\test.bat') Quote Link to comment Share on other sites More sharing options...
requinix Posted July 16, 2013 Share Posted July 16, 2013 The first one seems fine. What happens when you try it? The second one is missing a semicolon and has a tab character in the filename. The third one has syntax errors. Quote Link to comment Share on other sites More sharing options...
wmeredith Posted July 16, 2013 Author Share Posted July 16, 2013 (edited) Actually this worked; <?php exec('c:\\folder\\whatever.bat'); ?> Now I actually want a trigger in MYSQL to execute the php file after an INSERT of a certain table. Have any ideas? Edited July 16, 2013 by wmeredith Quote Link to comment Share on other sites More sharing options...
requinix Posted July 16, 2013 Share Posted July 16, 2013 MySQL can't do that. Make your code execute that file after it does the query. Quote Link to comment Share on other sites More sharing options...
wmeredith Posted August 8, 2013 Author Share Posted August 8, 2013 Thats what I finally decided to do, wrote my own code to execute the bat file. Thanks Quote Link to comment 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.