Jump to content

Exec function terminates??


Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/108902-exec-function-terminates/
Share on other sites

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?

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?

 

 

 

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.