CopyPastor

Detecting plagiarism made easy.

Score: 0.9613767486421307; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2017-06-09
by Matthijs Otterloo

Original Post

Original - Posted on 2013-11-21
by Havenard



            
Present in both answers; Present only in the new answer; Present only in the old answer;

To read the output of a process, `popen()` is the way to go. Your script will run in parallel with the program and you can interact with it by reading and writing it's output/input as if it was a file.
But if you just want to dump it's result straight to the user you can cut the crap and use `passthru()`:
echo '<pre>'; passthru($cmd); echo '</pre>';
Now if you want to display the output at run time as the program goes, you can do this:
while (@ ob_end_flush()); // end all output buffers if any
$proc = popen($cmd, 'r'); echo '<pre>'; while (!feof($proc)) { echo fread($proc, 4096); @ flush(); } echo '</pre>';

This code should run the command and push the output straight to the end user at run time.
To read the output of a process, `popen()` is the way to go. Your script will run in parallel with the program and you can interact with it by reading and writing it's output/input as if it was a file.
But if you just want to dump it's result straight to the user you can cut to the chase and use `passthru()`:
echo '<pre>'; passthru($cmd); echo '</pre>';
If you want to display the output at run time as the program goes, you can do this:
while (@ ob_end_flush()); // end all output buffers if any
$proc = popen($cmd, 'r'); echo '<pre>'; while (!feof($proc)) { echo fread($proc, 4096); @ flush(); } echo '</pre>';

This code should run the command and push the output straight to the end user at run time.

        
Present in both answers; Present only in the new answer; Present only in the old answer;