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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

debugging script that uses input from html form

Status
Not open for further replies.

bobbybobbertson

Programmer
Nov 9, 2001
119
US
I'm using a linux server.
I wrote a feedback form in html and i have it call a cgi script for processing. It is not working and I would like to debug it.

Is there a way to run the cgi from the command line on the unix machine and pass the parameters as though they came from the html document.

here is my cgi script:
###############################
###############################
#!/usr/bin/perl -w
use strict;
use CGI;

my $cgi = new CGI;
open OUTPUT_FILE, "> output.txt" or die "died";
foreach my $input_paramter ($cgi->param()) {
print OUTPUT_FILE "$input_paramter == $cgi->param($input_parameter)\n"
}
###############################
###############################


If I try and run this script from the command line, I get the following prompt:

(offline mode: enter name=value pairs on standard input)

I am then able to enter paramters, but I can't end it. It goes on forever!!! How do I tell it that I'm done entering paramters???

escape doesn't work...<ctrl>C kills the program...a blank line does nothing.
 
Try Ctrl-Z to end your input.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Ctrl-D, I think.

You can also facilitate debugging your code via your browser by replacing all of you calls to the 'die' function
with calls to a simple html closing routine. The die function sends it's errors to STDERR, thus making it useless in a CGI context (you never see the error in the browser).

Instead of,
open(FILE,&quot;<some_input.txt&quot;) or
die &quot;Failed to open file, $!&quot;;

Try,
open(FILE,&quot;<some_input.txt&quot;_ or
Ooops (&quot;Failed to open file, $!&quot;);

sub Ooops
{
my $complaint = shift;
print &quot;<p>$complaint</p>
</body></html>&quot;;
exit;
}

HTH
If you are new to Tek-Tips, please use descriptive titles, check the FAQs,
and beware the evil typo.
 
Thank gB, I couldn't remember if it was Ctrl-Z or Ctrl-D, and went with -Z because I know that's uses as an EOF character in some OS's (although, now that I think of it, I don't believe it is in Unix). Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
You might try the following perl. Hopefully it will direct fatal errors to your browser. Be sure and remove or comment out later after your script is running properly. Perl normally directs error to an errors log file. In Red Hat Linux the error log files are in /var/logs/http I think. I'm in windows right now and can't check.

use CGI qw( :all );
use CGI::Carp qw( fatalsToBrowser );


Leland
 
Hi,

I decided to go back and try some of my own advise. The code above works fine on my system with ActivePerl and windows running either IIS or apache. However, it didn't give me much help under Linux. I reviewed the perl documentation regarding Carp and came up with the code below. It directs more information to my browser when I placed an error in a script running the regular perl distributed by Red Hat.

use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
use CGI qw:)standard);
print header();
warningsToBrowser(1);


Leland
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top