Lunarpages Web Hosting Forum

Author Topic: Perl newbie needs help!  (Read 5763 times)

Offline nunos

  • Newbie
  • *
  • Posts: 3
Perl newbie needs help!
« on: September 21, 2009, 04:42:23 PM »
Hi there.

I have developed a perl script but I haven't been able to run it under lunarpages server. I run it in my local machine "wamp" server and it runs with no problem.

To simplify things, I even have tried this, with no success:

script.pl
Code: (perl) [Select]
#!/usr/bin/perl
print 'Hello World!';
edit: I already changed script.pl permissions to 755.

page.php:
Code: (php) [Select]
<html>
<head>
<title>SOME PAGE</title>
</head>
<?php 
exec
("script.pl"$output);
print_r($output);
?>

<body>
</body>
</html>

As you may or not know, $output holds evertything that is print to stdout from the script. In this case: "Hello World!"

All I get in the page.php is Array() whereas, in my local server I get is: Array ([0]=>"Hello World").

Can someone please tell me what I am doing wrong. Thanks.
« Last Edit: September 21, 2009, 04:44:52 PM by nunos »

Offline MrPhil

  • Senior Moderator
  • Berserker Poster
  • *****
  • Posts: 6428
Re: Perl newbie needs help!
« Reply #1 on: September 21, 2009, 06:02:09 PM »
The most likely thing is that there is some difference in the environments between your WAMP server and your LP server, e.g., safe mode "on" on one of them and "off" on the other. Read the PHP Manual entry to make sure you're using it the right way. You may want to set up this script:
Code: [Select]
<?php phpinfo(); ?>to see what all the various PHP settings are.

There's also the possibility that script.pl isn't being run, or at least, run in the way you think it is. Have you gone into cPanel and checked that your shebang path to Perl (such as /usr/bin/perl) is correct? Have you double checked that you got the permissions changed to 755? Is it in the same directory as page.php? Maybe you should ask for the return code (third parm) on the exec() call, to see if an error was reported. You're not trying to output to the browser (from script.pl), so I think the single "print" line should be OK. You might try "./script.pl" just in case there's something funny with the path.
Visit My Site

E-mail Me
-= From the ashes shall rise a sooty tern =-

Offline nunos

  • Newbie
  • *
  • Posts: 3
Re: Perl newbie needs help!
« Reply #2 on: September 23, 2009, 09:58:13 AM »
Thanks for your reply. I found what I was doing wrong. I didn't want to believe when I got it.
exec("script.pl"); doesn't work, but exec("perl script.pl") does. That was the problem. Thanks for your reply, though.

Cheers :smiling:

Offline MrPhil

  • Senior Moderator
  • Berserker Poster
  • *****
  • Posts: 6428
Re: Perl newbie needs help!
« Reply #3 on: September 23, 2009, 11:34:53 AM »
Well, that means that either you did not have the correct 'shebang' line, or you didn't in fact change permissions to 755, or "." was not in your path. Anyway, you've got it working, which in the end is what counts.
Visit My Site

E-mail Me
-= From the ashes shall rise a sooty tern =-

Offline nunos

  • Newbie
  • *
  • Posts: 3
Re: Perl newbie needs help!
« Reply #4 on: September 23, 2009, 01:02:39 PM »
Well, that means that either you did not have the correct 'shebang' line, or you didn't in fact change permissions to 755, or "." was not in your path. Anyway, you've got it working, which in the end is what counts.
Well I put the script in a folder and was able to call it without having to write "perl" inside the exec command. Thanks for all your help. Cheers  :smiling: