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
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?

Link to comment
Share on other sites

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?

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.