473,326 Members | 2,175 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,326 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 8107
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...
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
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...
1
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
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.