Jump to content

Why doesn't this code work? I want to send parameters from php to a perl script


donphp

Recommended Posts

Hi,

 

I want to send parameters from php to a perl script. The strange thing is that I can execute the perl script from the command line exactly as it is typed into the exec command of the php file and it works!

 

Here's my code:

 

PHP file:

======

<?php

 

print "Hello from PHP!<br>";

exec ('perl /<path to perl script>/test_perl_params.pl myparam=1',$result);

print $result[0];

print "<br>";

print "Bye! ";

 

?>

 

 

Perl File

======

#!/usr/bin/perl

use CGI;

$cgi = new CGI;

my $myparam=$cgi->param('myparam');

print "Hello from Perl[",$myparam,"]\n";

 

 

When I call the php script, the myparam is not populated in the print statement.

 

Any help would be much appreciated.

 

Thanks,

Don

I came up with a solution to the problem. The perl script now accepts the parameters and I can now pass parameters from php to perl .

 

Here's my new code:

 

PHP File:

======

<?php

print "Hello from PHP!<br>";

exec ('perl /<path to perl script>/test_perl_params.pl -myparam 1',$result);

print $result[0];

print "<br>";

print "Bye! ";

?>

 

Perl File

======

#!/usr/bin/perl

use Getopt::Long;

&Getopt::Long::Configure( 'pass_through', 'no_autoabbrev');

&Getopt::Long::GetOptions( 'myparam|m=s'                => \$myparam );

print "Hello from Perl[",$myparam,"]\n";

 

Cheers,

Don

 

P.S. I thought it was funny when my original post was moved from the "PHP Coding Help" to "Other >> Other Programming Languages" and then saw that it was a very long time since anyone posted or replied to anything in that forum. I must have been exiled for asking a question related to perl!!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.