View Full Version : Special settings on PC for IIS running CGI??
NevadaSam
04-28-2006, 06:05 PM
Special settings on PC for IIS running CGI??
I am learning Perl/cgi. My PC is set up with IIS installed and the latest Active Perl. I learnt and configured my cgi-bin to run scripts, but now I am having a problem as I am learning scripts that write to and read from a text file. My code is good; I can include it if necessary. My scripts work fine when I upload them to a website. And on my PC when I # out the lines which try to write to the text file there is no problem with the script reading the text file and printing the data. My SHEBANGs are correct and I have the html file pointed to the proper files and folders.
How do I have to set properties on my PC so scripts will write to text files?
Thanks, Samantha
KevinADC
04-28-2006, 07:53 PM
are you checking the server error logs or using die() or other means to try and track down the problem?
open(FH,'file.txt') or die "Can't open file.txt: $!";
Maybe something here will help:
http://www.tek-tips.com/faqs.cfm?fid=3559
I am not familiar with setting up perl and running CGI script on IIS so I can't offer much help.
NevadaSam
04-28-2006, 10:10 PM
Thanks Kevin: My cgi-bin is set up and working properly. I did have a problem before, but the properties are set and it has worked with all other scripts and works with this one except when asked to write to the file. It reads for a file ok.
thsi is my html code:<!super.html>
<html>
<head><title>WKRK-TV</title></head>
<body>
<h1>Super Bowl Survey Form</h1>
<FORM ACTION="http://localhost/cgi-bin/cvtc/superf.cgi" METHOD=POST>
<P><B>What did you think of the Super Bowl game?</B><BR>
<INPUT TYPE=radio NAME=Game VALUE=0> It was a great game.<BR>
<INPUT TYPE=radio NAME=Game VALUE=1> It was a boring game.<BR>
<INPUT TYPE=radio NAME=Game VALUE=2> I didn't watch the game.</P>
<P><B>Vote for your favorite Super Bowl commercial:</B><BR>
<INPUT TYPE=radio NAME=Commercial VALUE=Budweiser> Budweiser<BR>
<INPUT TYPE=radio NAME=Commercial VALUE=FedEx> FedEx<BR>
<INPUT TYPE=radio NAME=Commercial VALUE=MasterCard> MasterCard<BR>
<INPUT TYPE=radio NAME=Commercial VALUE=Pepsi> Pepsi</P>
<INPUT TYPE=submit VALUE="Submit Survey">
</FORM>
</BODY>
</HTML>
and this is my cgi script:
#!C:\Perl\bin
#super_pc.cgi - saves form data to a file, and creates a dynamic
#Web page that displays a message and survey statistics
print "Content-type: text/html\n\n";
use CGI qw(:standard);
use strict;
#declare variables
my ($game, $commercial, @records);
my @game_count = (0, 0, 0);
my %comm_count = ("Budweiser", 0,
"FedEx", 0,
"MasterCard", 0,
"Pepsi", 0);
#assign input items to variables
$game = param('Game');
$commercial = param('Commercial');
#save form data to a file
open(OUTFILE, ">>", "suvrey_pc.txt")
or die "Error opening survey.txt. $!, stopped";
print OUTFILE "$game,$commercial\n";
close(OUTFILE);
#calculate survey statistics
open(INFILE, "<", "survey_pc.txt")
or die "Error opening survey.txt. $!, stopped";
@records = <INFILE>;
close(INFILE);
foreach my $rec (@records) {
chomp($rec);
($game, $commercial) = split(/,/ , $rec);
$game_count [$game] = $game_count[$game] + 1;
$comm_count {$commercial} = $comm_count{$commercial} +1;
}
#generate HTML acknowledgment
print "<html><head><title>WKRK-TV</title></head>\n";
print "<body>\n";
print "<H2>Thank you for participating in our survey.</H2>\n";
print "<EM><B>What did you think of the Super Bowl game?</EM></B>\n";
print "<TABLE>\n";
print "<TR><TD>It was a great game.</TD> <TD>$game_count[0]</TD></TR>\n";
print "<TR><TD>It was a boring game.</TD> <TD>$game_count[1]</TD></TR>\n";
print "<TR><TD>I didn't watch the game.</TD><TD>$game_count[2]</TD></TR>\n";
print "</TABLE><BR>\n";
print "<EM><B>Vote for your favorite Super Bowl commercial:</EM></B>\n";
print "<TABLE>\n";
foreach my $key ("Budweiser", "FedEx", "MasterCard", "Pepsi") {
print "<tr><td>$key</td> <td>$comm_count{$key}</td></tr>\n";
}
print "</TABLE>\n";
print "</BODY></HTML>\n";
By the way: It is chapter 5 of the Web warrior Series CGI/Perl by Diane Zah from COURSE TECHNOLOGY of the Thomason Learning.
Thanks. I know by code is alright, However I do wonder why the "die" script I included does not tell what the error is.
KevinADC
04-28-2006, 11:35 PM
could it be so simple? Have you just mis-spelled the name of the file?
open(OUTFILE, ">>", "suvrey_pc.txt")
maybe that should be: survey_pc.txt
NevadaSam
04-29-2006, 01:44 AM
Yes that was a mistake in spelling, but not the problem. On the website it would create a file name suvrey_pc.txt to write data to and read from a file name survey_pc.txt
but on a pc it should write to the given file name even if misspelled which it does not.
Thanks for you attention to detail. I really need to know how to get script to create and write to file on my PC.
KevinADC
04-29-2006, 01:59 AM
yes, if the file does not exists, using '>>' or '>' should create a new file and write to it. Just for curiosity, try like this:
open(OUTFILE, ">>survey_pc.txt")
or die "Error opening survey.txt. $!, stopped";
I think it shouldn't make a difference but may as well try.
NevadaSam
04-29-2006, 03:43 AM
I tried the slight change of code but it did the same. When I click submit the next screen that comes up is blank. By viewing the source code which is created this is what was generated: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252"></HEAD>
<BODY onunload=""></BODY></HTML>
I have no idea where that comes from.
I am able to work around my PC problems by uploading the scripts to the Internet and runing it from there. It is a few extra steps but I get by.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.