Question

Basically my situation is as follows.

  1. Upload file
  2. Run external process on file (which generates another file)
  3. When external process is down, process the generated file.

Currently in PHP I run the program as follows:

$cmd = 'cd the_directory/; ./the_program'
system($cmd);

The program runs fine and everything, but the program at the end says "Press Enter to exit..." And thus Apache is hanging indefinitely as this program is waiting for user input. Our partner declares that they have this program integrated into their backend flawlessly and does not experience this issue. Up until now all external programs that i have executed in PHP exit without requiring user input which seems to be the norm for this situation.

It seems to me that the code should just simply not have the end message requiring user input. Am I missing something? Or is there a way to get around this? Or do they just need to change their code? Thanks!

Était-ce utile?

La solution

I think you should try proc_open.

With it you can not only execute an external command as a process, but also set pipes to get and send information to that process.

Take a close look to the third parameter of this function, and study the example in the PHP manual for this function, where you can see something like this:

fwrite($pipes[0], '<?php print_r($_ENV); ?>');

so, you can write what you need to the input pipe of the process you've just opened.

Autres conseils

if you use Windows environment:

$run_cmd = "cmd /c c:/app_folder/app.exe";
$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run($run_cmd, 0, false);

Note that the latter will cause the process window to close on end

If you use UNIX (haven't tested it myself yet):

exec('\app_folder\app &');
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top