usher_raymond82 Posted June 5, 2008 Share Posted June 5, 2008 Hi folks, I notice that the code after my exec function doesnt get executed. Example. $file = fopen("$bat_file", "w"); fwrite($file, 'cd C:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin start ABC.exe '.$config.' exit '); fclose($file); exec("cmd.exe /c $bat_file"); echo "Batch file complete"; I notice the batch file does run, but the msg after the exec function does not get printed at my browser. Does that mean the whole PHP script is terminated?? May I know what is wrong? Quote Link to comment https://forums.phpfreaks.com/topic/108902-exec-function-terminates/ Share on other sites More sharing options...
.josh Posted June 5, 2008 Share Posted June 5, 2008 does the batch file complete it's run? because unless you redirect the output of the file to some other file or stream it will cause php to be put on hold until it's done..so it might be timing out your script Quote Link to comment https://forums.phpfreaks.com/topic/108902-exec-function-terminates/#findComment-558676 Share on other sites More sharing options...
usher_raymond82 Posted June 5, 2008 Author Share Posted June 5, 2008 Yes it does. the ABC.exe will download some files and place those files in a certain directory. I can see those 3 files. When you say output of the file, do you mean the output of the batch file or the output of ABC.exe? Quote Link to comment https://forums.phpfreaks.com/topic/108902-exec-function-terminates/#findComment-558684 Share on other sites More sharing options...
DarkWater Posted June 5, 2008 Share Posted June 5, 2008 The output of the whole process. P.S: Lol@windows. =P Quote Link to comment https://forums.phpfreaks.com/topic/108902-exec-function-terminates/#findComment-558685 Share on other sites More sharing options...
usher_raymond82 Posted June 5, 2008 Author Share Posted June 5, 2008 So you are suggesting I should actually exec("cmd.exe /c $bat_file", $output, $return); ???? Quote Link to comment https://forums.phpfreaks.com/topic/108902-exec-function-terminates/#findComment-558694 Share on other sites More sharing options...
.josh Posted June 5, 2008 Share Posted June 5, 2008 should you? I have no idea what your batch file is supposed to be doing or your script's intentions. Quote Link to comment https://forums.phpfreaks.com/topic/108902-exec-function-terminates/#findComment-558698 Share on other sites More sharing options...
usher_raymond82 Posted June 5, 2008 Author Share Posted June 5, 2008 I am writing a PHP script that needs to interface to the ABC.exe application which is going to download information from a server. That is why I created a batch file, that has the commands to invoke ABC.exe to do its job. With that, I tried using the exec function to start executing the batch file. Once ABC.exe has done its job, I can see information (in .txt) downloaded and placed on my desktop. The strange thing is, I somehow realised that the code after the exec() does not run....regardless how long / short the ABC.exe takes to do its job. Am I using the exec function in a wrong way? Quote Link to comment https://forums.phpfreaks.com/topic/108902-exec-function-terminates/#findComment-558701 Share on other sites More sharing options...
thebadbad Posted June 5, 2008 Share Posted June 5, 2008 Just be sure that ABC.exe is terminated, in order for the script to finish (is my guess). Quote Link to comment https://forums.phpfreaks.com/topic/108902-exec-function-terminates/#findComment-558711 Share on other sites More sharing options...
usher_raymond82 Posted June 5, 2008 Author Share Posted June 5, 2008 It should be terminated. ABC.exe appears when the batch file runs and then goes away in the Task Manager when completes. Quote Link to comment https://forums.phpfreaks.com/topic/108902-exec-function-terminates/#findComment-558713 Share on other sites More sharing options...
thebadbad Posted June 5, 2008 Share Posted June 5, 2008 Does the script appear to 'hang' when it's loaded, or does it finish loading? Quote Link to comment https://forums.phpfreaks.com/topic/108902-exec-function-terminates/#findComment-558719 Share on other sites More sharing options...
usher_raymond82 Posted June 5, 2008 Author Share Posted June 5, 2008 It appears to hang, behavior is something like waiting for ABC.exe to finish dowlonading its files. Quote Link to comment https://forums.phpfreaks.com/topic/108902-exec-function-terminates/#findComment-558722 Share on other sites More sharing options...
thebadbad Posted June 5, 2008 Share Posted June 5, 2008 You could try to remove the start ABC.exe '.$config.' line, to see if it's ABC.exe halting the script. Quote Link to comment https://forums.phpfreaks.com/topic/108902-exec-function-terminates/#findComment-558726 Share on other sites More sharing options...
.josh Posted June 5, 2008 Share Posted June 5, 2008 does php have read permissions for cmd.exe? simplest way to do that is to make a copy of it in php.exe's directory. Quote Link to comment https://forums.phpfreaks.com/topic/108902-exec-function-terminates/#findComment-558727 Share on other sites More sharing options...
usher_raymond82 Posted June 5, 2008 Author Share Posted June 5, 2008 You could try to remove the start ABC.exe '.$config.' line, to see if it's ABC.exe halting the script. Yes. When I remove the line, the echo msg does get printed. In other words, I changed my code to $file = fopen("$bat_file", "w"); fwrite($file, 'cd C:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin exit '); fclose($file); exec("cmd.exe /c $bat_file > C:/temp/test.txt"); echo "Batch file complete"; The output of the test.txt is C:\Program Files\Apache Software Foundation\Apache2.2\htdocs>cd C:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin C:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin>exit If ABC.exe is the cause, what other methods / options do I have to run ABC.exe without halting the PHP script? Quote Link to comment https://forums.phpfreaks.com/topic/108902-exec-function-terminates/#findComment-558737 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.