Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Pass http Parameters from PHP to Perl Script that Is Called By PHP Using System or ShellExec

Avatar of Randall-B
Randall-B asked on
Web Languages and StandardsPHP
21 Comments1 Solution687 ViewsLast Modified:
Both of the following methods work to run a Perl script from within PHP, and grab the Perl script's output. Problem is, they are supposed to be able to pass http parameters to Perl, but they don't.  
    For example, the "?document=123" in the following URL is not getting passed into Perl:  myphpscript.php?document=123 . (Although in Http:Q_22081365 I thought it worked right, I just discovered my Perl script actually had the parameter hard-coded. When I removed the hard-coded variable, I discovered the PHP script is not really passing the parameters into Perl.)

METHOD 1:
<?php
 $document = $_GET['doc'];
   ob_start();
     system('/usr/local/bin/perl /usr/www/users/myuser/cgi-bin/perlscript.cgi -doc '.$document, $output);
   $output = ob_get_contents();
  ob_end_clean();
echo $output";
?>

Note: the following is all one line, with a space between "perl" and "/usr/" :    
      system('/usr/local/bin/perl /usr/www/users/myuser/cgi-bin/perlscript.cgi -doc '.$document, $output);

METHOD 2:
 <?php
   $document = $_GET['doc'];
$output = shell_exec('/usr/local/bin/perl
/usr/www/users/myuser/cgi-bin/perlscript.cgi -doc '.$document);
 echo $output;
?>

Note: the following is all one line, with a space between "perl" and "/usr/" :
$output = shell_exec('/usr/local/bin/perl
/usr/www/users/myuser/cgi-bin/perlscript.cgi -doc '.$document);

Experts, please: is there a way to make this work?  (I know "virtual" will pass the parameters, but Virtual echos the whole Perl output to the screen; and I don't want to echo the Perl output to the screen; I only want to capture it in my php script. Shell_exec or System will place the Perl output into a PHP variable that I can use in the PHP script, if I could just get the parameter to pass properly.)
ASKER CERTIFIED SOLUTION
Avatar of DarthMod
DarthModFlag of United States of America image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 21 Comments.
See Answers