Forum Moderators: coopster

Message Too Old, No Replies

PHP and Perl Problem

PHP isn't launching Perl script on IIS 7

         

Incog

11:48 am on May 14, 2009 (gmt 0)

10+ Year Member



Hi all,
I'm trying to set up a site on WinServer2008 using IIS 7 that makes use of a php page that launches a perl script. My php seems to be working as I would expect, the file test.php including:

<?php
echo exec("dir");
echo("<br/>Hello!<br/>");
?>

Outputs:
2 Dir(s) 235,264,655,360 bytes free
Hello!
when viewed in IExplorer. However, when I try

<?php
echo exec("perl script.pl");
echo("<br/>Hello!<br/>");
?>

All the output is:
Hello!

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.

rocknbil

4:12 pm on May 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome aboard Incog.

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 . . .

Incog

10:13 pm on May 14, 2009 (gmt 0)

10+ Year Member



Thanks for the help, rocknbil, but full paths to either the executable or the script (or both) didn't seem to take, and by my tests system seems to exhibit the same behaviour as exec on my setup (ie, will open notepad, perl won't run).
I'm definately starting to appriciate people's issues with Windows servers, I never realised how much I was taking for granted in Linux :)

rocknbil

3:15 am on May 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



(ie, will open notepad, perl won't run).

Wait a sec - you're testing this locally?

Have you tried putting it on an actual domain/web site and calling it remotely from a browser?