469,362 Members | 2,287 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,362 developers. It's quick & easy.

What should be the Shebang line in a CGI script?

135 100+
I've tried the following and unable to run the CGI script:

#!c:/program files/perl/perl
#!/usr/bin/perl
#!C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/

thank you
Sep 8 '07 #1
12 5852
numberwhun
3,503 Expert Mod 2GB
The shebang line in Windows is typically ignored. But, according to others here on TSDN, Apache will see it and see that Taint mode is turned on if you have it specified as:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -wT
  2.  
On Unix, the shebang should look like this, but should ALWAYS point to your Perl executable. It should not point to your Apached cgi-bin directory or any directory for that matter, without the executable name included.

Regards,

Jeff
Sep 8 '07 #2
KevinADC
4,059 Expert 2GB
Yes, point the shebag line to perl, not apache:

#!c:\perl\bin\perl.exe

Since windows in case-insensitive you can use all lower-case or any case.

If you put perl in the command path, you can simply use:

#!perl

You can also setup apache to use no shebang line on windows. I forget how but maybe someone in the apache forum knows. I know it's one of the apache directives, but I forget which and I am too lazy to google for it.

Another good thing to be aware of with windows is that you can use forward slashes in path statements:

c:/perl/bin/perl.exe

works just as well and is safer in perl code to avoid meta character confusion. A common misconception is that perl does not care if you use forward or back-slashes in path statements and this is why it works with windows. That is true, perl does not care, but windows natively supports either convention, it really has nothing to do with perl. All versions of windows, since the beginning, support forward or back-slashes in path statements. But DOS does not. So if you ever have to shell out to DOS for something you must use back-slashes in directory paths. Forward-slashes are command line switches in DOS.
Sep 8 '07 #3
patelxxx
135 100+
Numberwhun and Kevin,

Thanks it's ok now, I can actually run .CGI in my browser.

However just need help when sending an actual FORM to the .cgi script, do I need the FORM (i.e. post.html file) in an particular folder too?

Currently my .html file is on my desktop (post.htm) and my action line in this template is: <form action="/cgi-bin/post2.cgi" method="POST">

When I click on post.html and fill out the FORM and click submit I get the following error: "The page cannot be displayed".

Where am I going wrong now? I'm seeking help from you as no one from the Apache Forum responds at all.

Thanks guy's
Sep 12 '07 #4
numberwhun
3,503 Expert Mod 2GB
Your browser will display and HTML file the way it was designed no matter where the file resides. But, your webserver can only provide the page if it is in your document root. You need to look at your Apache configuration and see what that is set to. That is what you should use. My suggestion is to find out what folder it is and then make a shortcut to it on your desktop(in windows).

Once you put it in your document root, you can load the form like so on your local machine:

localhost/form.html

If you just type localhost in your browser and apache is running, the web server will send to your browser the index.html file that is in your defined document root.

Regards,

Jeff
Sep 12 '07 #5
patelxxx
135 100+
Jeff,

My Document Root location is as follows: DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs"

I have placed my .html files in this location and still I get the same error:
The page cannot be displayed

Cheers
Sep 12 '07 #6
numberwhun
3,503 Expert Mod 2GB
First, is the apache httpd service started and running? Second, what is the URL you are trying to load? Third, what is the html file called?

Regards,

Jeff
Sep 12 '07 #7
patelxxx
135 100+
1) The Apache httpd service is Running (as the green light in the bottom is on).
2) URL i'm loading up: http://localhost/post.html
3) HTML file is called: post.html (placed in DocumentRoot Folder)
4) CGI file is located Apache2.2/cgi-bin/post2.cgi

post.html coding:

[HTML]<html><head><title>Post.html</title></head>
<body>

<form action="/cgi-bin/post2.cgi" method="POST">
<pre>
Your Name: <input type="text" name="name">
Email Address: <input type="text" name="email">
Age: <input type="text" name="age">
Favorite Color: <input type="text" name="favorite_color">
</pre>
<input type="submit" value="Send">
<input type="reset" value="Clear Form">
</form>

</body>
</html>[/HTML]
Sep 12 '07 #8
KevinADC
4,059 Expert 2GB
"page can not be displayed" is displayed by Internet Explorer when there is no connection to the server at all. So it sounds like you have not started apache before trying to connect to it.
Sep 12 '07 #9
numberwhun
3,503 Expert Mod 2GB
I have to agree with Kevin.

If you are on Windows, then try:

apache -k restart

If that doesn't work, then you will have to visit the Apache forum and try to find out why your Apache installation is not serving pages to your browser.

Regards,

Jeff
Sep 12 '07 #10
patelxxx
135 100+
Where do I type in apache -k restart?

I think apache is working because I can run the following scripts:
http://localhost/cgi-bin/browser.cgi
http://localhost/cgi-bin/hello.cgi
http://localhost/cgi-bin/names.cgi


However it's when I submit the FORM (post.html) that loads up fine, however it's when I submit the form I get the error.

I've also followed: http://httpd.apache.org/docs/2.0/en/urlmapping.html#proxy

In the error log I get the following message:
[Fri Oct 12 21:11:29 2007] [error] [client 0.0.0.0] script not found or unable to stat: C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/post2.cgi, referer: http://localhost/post.html
Sep 12 '07 #11
KevinADC
4,059 Expert 2GB
some kind of a path problem it looks like:

C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/post2.cgi

I would think that would be:

C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/cgi-bin/post2.cgi

although I am not sure since I don't have apache2.2 installed an I am not familiar with how it is setup.
Sep 12 '07 #12
patelxxx
135 100+
kevin / numberwhum,

guess what it's resolved. The problem was very simple, my CGI was named post2.cgi.cgi hence the FORM couldn't find the file.

Thank very much again, now starts my Perl journey.
Sep 14 '07 #13

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by deko | last post: by
5 posts views Thread by rbt | last post: by
11 posts views Thread by Joerg Schuster | last post: by
121 posts views Thread by typingcat | last post: by
4 posts views Thread by Jozef | last post: by
5 posts views Thread by veracon | last post: by
13 posts views Thread by Chris Lasher | last post: by
13 posts views Thread by notbob | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.