This must be easy, but I'm missing something...
I want to execute a Perl script, and capture ALL its output into a PHP
variable. Here are my 2 files:
-------------------------------------
test3.pl
-------------------------------------
print "PERL Hello from Perl! (plain print)<br>\n";
print STDERR "PERL This is text sent to STDERR<br>\n";
$output="PERL Some output:<br>\n";
for ($i=0; $i<5; $i++) {
print STDOUT "PERL $i: This is text sent to STDOUT<br>\n";
$output .= "PERL line $i of output---<br>\n";
}
print $output;
exit;
-------------------------------------
passthru3.php
-------------------------------------
<?
$command = "/usr/local/bin/perl";
$pgm = "test3.pl";
print "PHP: Before passthru, in PHP...<br>\n";
$result=passthru("$command $pgm your_variable");
print "PHP: After passthru, result=($result)<br>\n";
?>
-------------------------------------
OUTPUT:
-------------------------------------
PHP: Before passthru, in PHP...
PERL Hello from Perl! (plain print)
PERL 0: This is text sent to STDOUT
PERL 1: This is text sent to STDOUT
PERL 2: This is text sent to STDOUT
PERL 3: This is text sent to STDOUT
PERL 4: This is text sent to STDOUT
PERL Some output:
PERL line 0 of output---
PERL line 1 of output---
PERL line 2 of output---
PERL line 3 of output---
PERL line 4 of output---
PHP: After passthru, result=()
I'd like to be able to capture all the output in $result, and only
show it
when I feel like it. The passthru() doesn't interfere, but the
system() command supposedly only shows the last line? What am I
missing?