Jump to content

PHP exec() Prevents Subsequent Output


OtagoHarbour
 Share

Recommended Posts

In the following code<?php exec('MyExecutable -i Input.txt -o Output.txt'); ?> <script type="text/javascript"> alert("Some message"); </script> <?php?>the exec() call runs fine and does exactly what I would like it to do. But the alert box doesn't come up. Also I get no output from echo "Whatever";does not give any output. However, when I comment out the exec() call, the alert box (at least) comes up.Is there a way to run the exec call and still get output afterward? Also I noticed that, for whatever reason, the second and third arguments of exec() (output and return) are deprecated or at least deprecated in so far as being passed by reference. How are they supposed to be used now?Thanks,Peter.

Link to comment
Share on other sites

Are you sure the program finishes? If the program doesn't finish, PHP will hang. I don't see anything about the other two parameters being deprecated. Pass by reference doesn't have anything to do with deprecation. If you pass an array variable as the second parameter and another variable as a third, the array will have the lines that the program outputted and the other variable will have the return status as an integer.

Link to comment
Share on other sites

Are you sure the program finishes? If the program doesn't finish, PHP will hang. I don't see anything about the other two parameters being deprecated. Pass by reference doesn't have anything to do with deprecation. If you pass an array variable as the second parameter and another variable as a third, the array will have the lines that the program outputted and the other variable will have the return status as an integer.
It does seem to be related to the program but the program does run to completion on the desktop. It has 3 refinement cycles. If I only use 2 cycles then I have no problem with PHP exec(). I get the alert box as expected. However when I use 3 refinement cycles then all of the following PHP and JavaScript code seems to be ignored. The program does finish since it generates an output file on the disk as expected, the "wait" graphic on Firefox stops and it says "Done", instead of "Waiting for localhost", at the bottom at the bottom.Thanks,Peter
Link to comment
Share on other sites

About all I can say is to make sure the level of error reporting is as high as it gets. It sounds like there's an error happening that you're not seeing, which could be PHP timing out because the program hasn't finished yet.

ini_set('display_errors', 1);error_reporting(E_ALL);

Link to comment
Share on other sites

About all I can say is to make sure the level of error reporting is as high as it gets. It sounds like there's an error happening that you're not seeing, which could be PHP timing out because the program hasn't finished yet.
ini_set('display_errors', 1);error_reporting(E_ALL);

The problem was that PHP was timing out. I addedset_time_limit(0);before the call to exec() and that fixed the problem.Thank you so much for your help,Peter.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...