Page does not stop loading when using exec in WAMP

Asked

Viewed 392 times

1

I need to make a PHP script that runs a program on the server, but the page doesn’t stop loading, it’s like it’s waiting for the process to be finished.

I already went to services.Msc and put the apache process to interact with my desktop, but it goes to another session, as if it were not mine.

My code is this:

<?php
    exec('C:\\teste.exe');
?>

2 answers

1

According to the job documentation exec(), PHP waits for the execution of the command, because the value returned by the function exec() is the last line of that implementation.

  • Right, and what you recommend I use to start a program in windows environment?

  • Try calling the following function: pclose(popen("start /B C:\\teste.exe", "r"));

  • The script runs and nothing happens, but if I put a file that does not exist, the script runs non-stop..

0

Exec waits for the end of the process to finish interpreting your code, a cool example for you to understand would be to do a test with the Notepad ("Notepad Windows.");

 <?php exec("notepad.exe"); ?>

Once it runs it will open the notepad, note that the page will be loading.... as soon as you close the notepad the execution will end.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.