donphp Posted October 10, 2010 Share Posted October 10, 2010 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 Link to comment https://forums.phpfreaks.com/topic/215528-why-doesnt-this-code-work-i-want-to-send-parameters-from-php-to-a-perl-script/ Share on other sites More sharing options...
donphp Posted October 10, 2010 Author Share Posted October 10, 2010 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!! Link to comment https://forums.phpfreaks.com/topic/215528-why-doesnt-this-code-work-i-want-to-send-parameters-from-php-to-a-perl-script/#findComment-1120806 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.