473,241 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,241 software developers and data experts.

Capturing PERL script output into PHP variable

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?
Jul 17 '05 #1
4 8098
Mark Wilson CPU <wi****@cpuworks.com> wrote:
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"; [snip] 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?


You probably have to redirect the output from stderr to stdout:
$result=passthru("$command $pgm your_variable 2>&1");

Jul 17 '05 #2
wi****@cpuworks.com (Mark Wilson CPU) wrote in message news:<3f**************************@posting.google. com>...
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:

<snip>

FWIW, check this <http://www.zend.com/php5/articles/php5-perl.php>

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/
Jul 17 '05 #3
Carved in mystic runes upon the very living rock, the last words of Mark
Wilson CPU of comp.lang.php make plain:
I want to execute a Perl script, and capture ALL its output into a PHP
variable. $result=passthru("$command $pgm your_variable");


passthru() doesn't return anything. That's what "void" means in the Fine
Manual.

Try http://www.php.net/manual/en/function.exec.php

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
Jul 17 '05 #4
wi****@cpuworks.com (Mark Wilson CPU) wrote
in message news:<3f**************************@posting.google. com>...

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's your problem:
$result=passthru("$command $pgm your_variable");


The correct way to use passthru() in your situation would be:

ob_start();
passthru("$command $pgm your_variable");
$result = ob_get_clean();

Now all output of the Perl script is captured in the $result variable.

Cheers,
NC
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: sam | last post by:
I have a function writen in Perl that takes a name-value list (array) as argument and returns a name-value list (array). My question is: How to call this function from PHP and get the returned...
5
by: Mike | last post by:
I'm trying to capture data that is created by launching a php file, for example the last 10 posts in a message forum. If last10.php is called directly in your browser you'll see hyperlinks to the...
5
by: Moosebumps | last post by:
I have a large set of Python scripts that interface with command line utilities (primarily Perforce). I am currently capturing ALL the text output in order to get results and such. I am using the...
4
by: Avi Kak | last post by:
Is there a Python function in any of the standard-distribution modules that does what the backticks do in Perl? I want to run an external command and I'd like its output to be captured directly...
1
by: andy.t.chou | last post by:
I need to be able to have a hidden field (signiture) with each output html file generated. # (Get the first and last name from the html form) $first_name = $q->param('FirstN'); $last_name =...
1
by: ebobnar | last post by:
I'm sure you all have seen how using the src argument in a script tag is essentially the same as including the body of the script within your page. For example: <script type="text/javascript"...
0
by: Kirt Loki Dankmyer | last post by:
So, I download the latest "stable" tar for perl (5.8.7) and try to compile it on the Solaris 8 (SPARC) box that I administrate. I try all sorts of different switches, but I can't get it to compile....
1
by: kurt | last post by:
I have a device that came with a perl script that will control the opening and closing of relays and also return their current state. I have the script running as a server side include. The state...
4
by: sonu2die4 | last post by:
Hi, I have the following perl script working for me.I am accesing the database from my perl script using use Net::Telnet(); package. I am not using DBI package.as I stated earlier the following...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.