Forum Moderators: coopster
<?php
echo exec("dir");
echo("<br/>Hello!<br/>");
?>
<?php
echo exec("perl script.pl");
echo("<br/>Hello!<br/>");
?>
Even though when 'perl script.pl' is run on the command prompt it correctly outputs "Perl success!". I have also tried to run a script which creates a new file in the wwwroot directory which runs correctly from the command prompt but has no effect (or maybe doesn't even run) when called from php.
Any and all advice is appriciated in getting this to work, no matter how simple it may seem. Odds are I've overlooked some minor step that's ruining the whole thing.
I abhor working with Windows based servers. But from what I remember, getting inline commands to execute was pretty tricky.
First, make sure the script can be executed where it "lives" (looks like you've done that) and also make sure the executing script user (your php "user") has permissions to execute that script.
Next, understand what's happening. You are saying to echo (print to screen) the result of an exec command. From the PHP docs [us3.php.net], you could try using an output variable as shown and echo the output:
var $output = '';
exec("perl script.pl",$output);
echo ($output);
I have no idea if this will even work, I use system() below . . .
The alternative, and one I've had more success with, is system() [us2.php.net]. System() differs from exec in that it returns a value:
$output='';
$output = system("perl script.pl");
echo $output;
Ore even your one-liner might do:
echo system("perl script.pl");
A last caveat, even though it's probably in the same directory as your php script, you may need to specify the full path to the script, and here is why. On some systems, executing perl makes wherever perl is the current directory. script.pl lives in your domain, not the perl directory. I know this is really screwed up and should not be the case, but I've seen it. You may need to do
$output='';
$output = system("perl C:\full\path\to\script.pl");
echo $output;
Now you know one of the many reasons I abhor Windows servers . . .