I have made a perl script which I would like to run from PHP.
When I do a normal example like
PHP:
exec("perl test.pl",$output);
echo '<pre>'; print_r(array_values($output)); echo '</pre>';
PERL:
#!/usr/bin/perl -s
print "Hiii. This is perl executing in PHP";
And it prints out: Hiii. This is perl executing in PHP in PHP
But when I add my other Perl script (test2):
#!/usr/bin/perl -s
# Function definition
use test_sub qw( :all ) ;
use strict;
use warnings;
if ($ARGV[0] eq "te")
{
printf("te chosen to(%d)\n",$ARGV[1]);
te($ARGV[1]);
}
And the new PHP looks like:
exec("perl test2.pl",$output);
echo '<pre>'; print_r(array_values($output)); echo '</pre>';
I know that there should be a warning atleast eventhough i dont use any arguments, but nothing appears to be in the $output.
Even with arguments in PHP:
exec("perl test2.pl te 1",$output);
echo '<pre>'; print_r(array_values($output)); echo '</pre>';
Nothing appears. I have tried to see if the file in executable with the function
is_executable('test2.pl')
Which it is.
This runs on a Raspberry PI 2 with Arch and I do not know if this could have any impact?
The other perl file which is referred to is:
package test_sub;
use strict;
use warnings;
use Exporter qw(import);
use Time::HiRes qw(usleep);
our @EXPORT_OK = qw(te);
our %EXPORT_TAGS = (all => \@EXPORT_OK );
sub te {
my @var = @_;
printf("settingup te for %d",$var);
}
I have checked in the terminal for it self and here it works as intended. But I cannot get it to work through PHP.
Any help would be much appreciated.
Update 1
I have found out that if I add the line:
use test_sub qw( :all ) ;
To the test.pl script which worked it stops giving an output asswell.
-sflag enabled in your Perl shebang?