Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

linking to perl in xampp apache cgi

Status
Not open for further replies.

PROFESSORSPARKIE

Instructor
Oct 24, 2002
181
US
Can anyone help me with the following cgi(perl) program execution?
Here is what I am doing.

1. Apache xampp is installed on a Windows XP system.
2. Xampp Control Panel says that Apache is running.
3. I see the Apache icon on the Start Bar.
4. I placed the following HTML file in “C:\apache\htdocs” folder as “SIMPLE.HTML”.

<html>
<body>
<h3>
<center>
<TABLE WIDTH=80% BORDER=13 BORDERCOLOR=BLUE>
<TD>
<FORM METHOD="POST" ACTION="simple.pl">
<CENTER>
<TABLE BORDER=1>
<TR> <TD>- REVIEW THE COMPLETE INVENTORY FILE STATUS. -</TD></TD>
</TABLE>
<BR>
<INPUT TYPE="SUBMIT" VALUE="CLICK TO DISPLAY ALL OF THE RECORDS">
</CENTER>
</FORM>
</td>
</table>
</center>
</body>
</html>

5. I placed the following cgi(perl) file in “C:\apache\htdocs” folder as “SIMPLE>PL”.

#!"\xampp\perl\bin\perl.exe"

print "Content-Type: text/html\n\n";#!/usr/bin/perl
#**********************************************************************
#* THIS PROGRAM READS THE STANDARD INPUT AND THEN *
#* LISTS OUT A TEXT FILE & PRINTS TO THE STANDARD OUTPUT *
#**********************************************************************
print "<HTML><HEAD><TITLE>Here comes a listing!\n</TITLE></HEAD>";
print "<BODY>";
print "<BR>";
if (open(INV_IN, "<c:\\xampp\\htdocs\\INV_RPT.TXT"))
{
# run this listing if open succeeds
}
else
{
print "Cannot open Mydatafile!\n";
exit 1;
}
while(defined($a=<INV_IN>))
{
print $a;
print "<BR>\n";
}
close(Myfile);
print "file Myfile listed.\n";
print "<BR>\n";
print "</BODY></HTML>\n";
exit 0;

THEN:
6. I have placed the files in the same folders.
When I use the latest Mozilla browser to load the “html” web page and execute it the web page loads OK and when I select the <FORM> tag to load & run the perl program I just get a listing of the perl program.

After it failed I did the following and tried to use the “cgi” option.
I placed the same file in “C:\apache\htdocs” folder as “simple.cgi” & updated the <form> tag.
I also placed the perl program as “smple.pl” & “simple.cgi” in the “C:\apache\cgi.bin” folder and restested.

The browser finds the files, the perl interpreter is in it proper location “c:\perl\bin\perl” and in “c:\xampp\perl\bin\perl” but is not executed. I have tried being more & less speciic on the shbang command.

I have tried every combination with no success.

I write, using a cloud hosted web site with similar programs with no problems. The problem is that, the Apache server and/or the browser are not working together to catch the web page ACTION="simple.pl" request and passing it to perl.


Computer thought: I teach a lot of programming so I can learn. You can never learn it all.
 
As you have seen POST doesn't mean go execute this program.

And you didn't really get the idea of CGI/Perl.

Here a some code from ActivePerl's documentation on the CGI module.

Code:
#!/usr/local/bin/perl -w
   use CGI;                             # load CGI routines
   $q = CGI->new;                        # create new CGI object
   print $q->header,                    # create the HTTP header
         $q->start_html('hello world'), # start the HTML
         $q->h1('hello world'),         # level 1 header
         $q->end_html;                  # end the HTML

You can basically take code like this rename the suffix to .cgi and it will run (there is also a way to tell the server to just run it even if it has the .pl suffix).

Now what is going on here is that Perl loads the CGI module, this module (and CGI for that matter) is the "language" of how to talk to the server to get things done (and to get information back).

What is the "done"? In the above case it creates a web page that is displayed when the user select the link like
There are functions for creating basic HTML pages. The idea here is that the Perl script creates the web page on the fly. There are other calls to the CGI information to get for instance what the user type into a text field:

Code:
   use CGI qw/:standard/;
   print 
       header,
       start_html('Simple Script'),
       h1('Simple Script'),
       start_form,
       "What's your name? ",textfield('name'),p,
       "What's the combination?",
       checkbox_group(-name=>'words',
                      -values=>['eenie','meenie','minie','moe'],
                      -defaults=>['eenie','moe']),p,
       "What's your favorite color?",
       popup_menu(-name=>'color',
                  -values=>['red','green','blue','chartreuse']),p,
       submit,
       end_form,
       hr,"\n";

    if (param) {
       print 
           "Your name is ",em(param('name')),p,
           "The keywords are: ",em(join(", ",param('words'))),p,
           "Your favorite color is ",em(param('color')),".\n";
    }
    print end_html;
 
Actually let me tell you why your post just listed the Perl file. The configuration of your server tell it what it should do with each file type, and the file types that it doesn't know about are just sent to the user. Since your server is not configured to run the Perl script this is what happens.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top