methtical Posted February 5, 2008 Share Posted February 5, 2008 Hi, If anyone can help me please? I would like to execute a batch file from a php script. I have simply got the following code at the moment: echo exec('load.bat'); after submission the page is doing something (loading) but nothing executes. The batch file loads fine when i click it manually! any ideas please? thanks! Quote Link to comment https://forums.phpfreaks.com/topic/89561-exec-a-batch-file-from-a-php-script/ Share on other sites More sharing options...
PHP Monkeh Posted February 5, 2008 Share Posted February 5, 2008 Remove echo So it's just exec('load.bat'); Quote Link to comment https://forums.phpfreaks.com/topic/89561-exec-a-batch-file-from-a-php-script/#findComment-458822 Share on other sites More sharing options...
methtical Posted February 5, 2008 Author Share Posted February 5, 2008 Hi, Thanks, i removed the echo, its now looking like: exec('c:\load.bat'); The batch file manually is executing an .exe! the php script seems to be loading the batch file but for some some odd reason its crashing the program. Any ideas? cheers Quote Link to comment https://forums.phpfreaks.com/topic/89561-exec-a-batch-file-from-a-php-script/#findComment-458841 Share on other sites More sharing options...
trq Posted February 5, 2008 Share Posted February 5, 2008 What does this program do? exec will not return untill the program it executes is finished. Quote Link to comment https://forums.phpfreaks.com/topic/89561-exec-a-batch-file-from-a-php-script/#findComment-458842 Share on other sites More sharing options...
methtical Posted February 5, 2008 Author Share Posted February 5, 2008 It will attempt to open a setup exe... Quote Link to comment https://forums.phpfreaks.com/topic/89561-exec-a-batch-file-from-a-php-script/#findComment-458848 Share on other sites More sharing options...
methtical Posted February 5, 2008 Author Share Posted February 5, 2008 clicking on the batch file manually runs the .exe fine. There seems to be a problem in the function exec(); or i may be using the wrong one! :-\ Quote Link to comment https://forums.phpfreaks.com/topic/89561-exec-a-batch-file-from-a-php-script/#findComment-458852 Share on other sites More sharing options...
PHP Monkeh Posted February 5, 2008 Share Posted February 5, 2008 Are you wanting the program to download and execute for the user? Or are you wanting it to execute on the server Quote Link to comment https://forums.phpfreaks.com/topic/89561-exec-a-batch-file-from-a-php-script/#findComment-458857 Share on other sites More sharing options...
methtical Posted February 5, 2008 Author Share Posted February 5, 2008 at the moment its all testing a technique, ive got everything local. To clear up the problem, the batch file (load.BAT) contains the following: cd "C:\Documents and Settings\methtical\Desktop\\Software" Serv.exe This fires the Serv.exe up when i click on the load.BAT perfectly. What im doing as a test is to send a command from php that can do it for me.. i.e exec('C:\load.bat'); Eventually im looking at a web interface that wont specifically execute an exe but to execute batch files in general. If anyone can help, it would be much appreciated! thanks! Quote Link to comment https://forums.phpfreaks.com/topic/89561-exec-a-batch-file-from-a-php-script/#findComment-458869 Share on other sites More sharing options...
trq Posted February 5, 2008 Share Posted February 5, 2008 How long does Serv.exe take to complete? Thats how long it will take before exec will return control to your script. Also, I think you'll find any program which attempts to open a window will not run. The apache process simply doesn't have permissions to do this. (At least on Linux anyway) Quote Link to comment https://forums.phpfreaks.com/topic/89561-exec-a-batch-file-from-a-php-script/#findComment-458877 Share on other sites More sharing options...
methtical Posted February 5, 2008 Author Share Posted February 5, 2008 would running exec(); just to run a batch file be ok? if not no worries..thanks for the help though! Quote Link to comment https://forums.phpfreaks.com/topic/89561-exec-a-batch-file-from-a-php-script/#findComment-458882 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.