Jump to Navigation

049 - How to call a Perl script from PHP

The exec() function is best-suited for executing an operating system-level application intended
to continue in server background. Even there is a perl script you want to execute, it is easy to do that.

Perl script (languages.pl) :

##  Sample program for PHP exec()
##print "Content-type: text/plain; charset=iso-8859-1\n\n";
my @languages = qw[perl php python java c];
foreach $language (@languages) {
print $language . "<br />";

PHP script :

$outcome = exec("languages.pl", $results);
foreach ($results as $result) echo $result;

If you are running Linux, chances are very good that you could run this example immediately
because Perl is installed on every respectable distribution. If you are running Windows, check out
ActiveState's ActivePerl distribution. You have to install it.

Main menu 2

Story | by Dr. Radut