To Call A Perl Script As An External Program In A Php Script
2
0
Entering edit mode
12.6 years ago
grosy ▴ 100

Dear Biostars!!

I want to call a perl script as an external program in a PHP script, once it has finished running the PHP script should send back the output to a html page. I tried using exec command to call the perl script but it dint work out. please help with this simple perl script, so that i can try using the same !

Perl script:

#!/usr/bin/perl -s

$var1 = 'high';

print $var1;

Thanks ahead of time !!

perl web • 25k views
ADD COMMENT
1
Entering edit mode

This would be a great question for stackexchange or perlmonks, not bioinformatics related.

ADD REPLY
0
Entering edit mode

Will this help? If not search in stackoverflow

ADD REPLY
0
Entering edit mode

Please explain how this is related to bioinformatics.

ADD REPLY
1
Entering edit mode
12.6 years ago
Lee Katz ★ 3.2k

You'll have to print something to transfer information from the perl script to PHP, so that PHP can read the output. You should consider what kind of data you need to transfer. For example, if you need to transfer sequence data, then print a GenBank or FASTA file. However if it is more complicated, then you might consider printing out XML.

If you print out XML, then look at CPAN to see what modules there are to create XML. PHP has easy XML classes too.

ADD COMMENT
1
Entering edit mode
12.4 years ago

First create a Perl program like

print "Hiii. This is perl executing in PHP";

Now to call this perl program, let us say "perl.pl", u can either use shell_exec() function or passthru function of php. for example, test.php

<php
$result = shell_exec('perl.pl'); # in linux $result = shell_exec(perl perl.pl)
echo $result;
?>

Make sure that this test.php is running from any php server and both files are in same folder. you can pass arguments to perl script with @ARGV function of perl.

ADD COMMENT

Login before adding your answer.

Traffic: 2134 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6