Jump to content

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


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!!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.