7 Replies - 20464 Views - Last Post: 22 May 2009 - 09:44 PM

#1 VernonDozier  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 56
  • Joined: 06-January 08

Trying to call Perl script from HTML

Posted 18 May 2009 - 03:52 PM

I'm trying to execute a Perl script from within an HTML page. The Perl script displays "banana". The result should be this:

apple
banana
orange



Instead the result is this:

apple
orange



"banana" is not displayed. Here is my HTML file:

<html>
  <body>
	apple <br>
	<!--#exec cgi="Fruit.pl"-->
	orange <br>
  </body>
</html>



Here's my Perl program (Fruit.pl)

#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "banana";



Does this look correct?

Is This A Good Question/Topic? 0
  • +

Replies To: Trying to call Perl script from HTML

#2 KevinADC  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 27
  • View blog
  • Posts: 401
  • Joined: 23-January 07

Re: Trying to call Perl script from HTML

Posted 18 May 2009 - 04:21 PM

There is on SSI error? Maybe you need a fuller path to the perl file:

<!--#exec cgi="machine/path/to/Fruit.pl"-->

When you run it like that I am not sure if its a URL or a machine path, but I think its a machine path. You might also want to look at using the "virtual" SSI tag instead of exec.

As far as your perl code goes it looks OK, but you might want to add a <br> tag in there:

#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "banana<br>";


This post has been edited by KevinADC: 18 May 2009 - 04:22 PM

Was This Post Helpful? 0
  • +
  • -

#3 VernonDozier  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 56
  • Joined: 06-January 08

Re: Trying to call Perl script from HTML

Posted 18 May 2009 - 04:51 PM

View PostKevinADC, on 18 May, 2009 - 03:21 PM, said:

There is on SSI error? Maybe you need a fuller path to the perl file:

<!--#exec cgi="machine/path/to/Fruit.pl"-->

When you run it like that I am not sure if its a URL or a machine path, but I think its a machine path. You might also want to look at using the "virtual" SSI tag instead of exec.

As far as your perl code goes it looks OK, but you might want to add a <br> tag in there:

#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "banana<br>";



Interestingly enough, I get an Internal Server Error when I put the files in the cgi-bin directory, but I don't get that error when I have the files OUTSIDE of the cgi-bin directory. I just simply get "apple" and "orange", but no "banana". When I specify a bogus file that doesn't exist, like "abcd.pl", I get the same thing. No error message, no "banana". So I am wondering if that <!-- line is simply ignored if it's not in the cgi-bin folder? It doesn't seem to matter whether I put the whole path to the local machine or a URL and whether I use exec or virtual. Is there a way to get an error message or to find out if that line is simply ignored for debugging purposes? "Internal Server Error" isn't very descriptive. Thanks for the reply.
Was This Post Helpful? 0
  • +
  • -

#4 KevinADC  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 27
  • View blog
  • Posts: 401
  • Joined: 23-January 07

Re: Trying to call Perl script from HTML

Posted 18 May 2009 - 11:03 PM

Try using the virtual tag like I suggested and see if that helps.
Was This Post Helpful? 0
  • +
  • -

#5 dsherohman  Icon User is offline

  • Perl Parson
  • member icon

Reputation: 226
  • View blog
  • Posts: 654
  • Joined: 29-March 09

Re: Trying to call Perl script from HTML

Posted 19 May 2009 - 05:28 AM

View PostVernonDozier, on 18 May, 2009 - 11:51 PM, said:

Is there a way to get an error message or to find out if that line is simply ignored for debugging purposes? "Internal Server Error" isn't very descriptive. Thanks for the reply.

Take a look in your web server's error log (usually /var/log/apache/error_log or /var/log/httpd/error_log if you're using Apache on a unix-type system) and you should find a more detailed error message there.

Web servers generally send uninformative error messages to browsers because a: the typical web user won't be in a position to do anything about fixing it and b: giving out detailed information about what went wrong can tell an attacker exactly how to make things malfunction in a way that compromises the system.
Was This Post Helpful? 1
  • +
  • -

#6 VernonDozier  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 56
  • Joined: 06-January 08

Re: Trying to call Perl script from HTML

Posted 19 May 2009 - 09:27 AM

Thanks guys. I solved it. The perl file was fine as it was, though I did add the line break. There were a few things I needed to do. One, for sure, the perl file had to be in the cgi-bin folder. The html file could be anywhere, but I had to add this to the .htaccess file:

AddHandler server-parsed .shtml .html .htm
Options Indexes FollowSymLinks Includes



And the html file had to use virtual and the local machine path. It didn't like getting the full path. I was experimenting all over the place, but that was BEFORE changing the .htaccess file, so I would get the .html file correct, but it made no difference given the fact that .htaccess was wrong. Here is the html file.

<html>
  <body>
	apple <br>
	<!--#include virtual="/cgi-bin/Fruit.pl" -->
	orange <br>
  </body>
</html>



Again, thanks for the help and it's solved. Thanks for the tip on the error log too. That'll come in really handy. I guess it makes sense that you wouldn't want to display all the relevant info to the browser.
Was This Post Helpful? 0
  • +
  • -

#7 markstinson  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 22-May 09

Re: Trying to call Perl script from HTML

Posted 22 May 2009 - 06:36 PM

Also keep in mind, since you are using Serve Side Includes to exec and post back it's output to an HTML page, the calling page will already have the content-type delivered to the browser from the web server. You DO NOT need to include printing the content type in this example banana scenario - else you could foul up your post-processed document with TWO content-types.

Later, Mark S.

View PostVernonDozier, on 19 May, 2009 - 08:27 AM, said:

Thanks guys. I solved it. The perl file was fine as it was, though I did add the line break. There were a few things I needed to do. One, for sure, the perl file had to be in the cgi-bin folder. The html file could be anywhere, but I had to add this to the .htaccess file:

AddHandler server-parsed .shtml .html .htm
Options Indexes FollowSymLinks Includes



And the html file had to use virtual and the local machine path. It didn't like getting the full path. I was experimenting all over the place, but that was BEFORE changing the .htaccess file, so I would get the .html file correct, but it made no difference given the fact that .htaccess was wrong. Here is the html file.

<html>
  <body>
	apple <br>
	<!--#include virtual="/cgi-bin/Fruit.pl" -->
	orange <br>
  </body>
</html>



Again, thanks for the help and it's solved. Thanks for the tip on the error log too. That'll come in really handy. I guess it makes sense that you wouldn't want to display all the relevant info to the browser.

Was This Post Helpful? 0
  • +
  • -

#8 KevinADC  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 27
  • View blog
  • Posts: 401
  • Joined: 23-January 07

Re: Trying to call Perl script from HTML

Posted 22 May 2009 - 09:44 PM

View Postmarkstinson, on 22 May, 2009 - 05:36 PM, said:

Also keep in mind, since you are using Serve Side Includes to exec and post back it's output to an HTML page, the calling page will already have the content-type delivered to the browser from the web server. You DO NOT need to include printing the content type in this example banana scenario - else you could foul up your post-processed document with TWO content-types.

Later, Mark S.


You sure about that? Have you tried it? ;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1