This is a test version of Biostars. For the public version, visit https://www.biostars.org.
To Call A Perl Script As An External Program In A Php Script

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

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

Please explain how this is related to bioinformatics.

2 answers

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.

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.

Log in to answer this question.