[ back to toc ]

perl 5: file I/O through IIS

Date: 2002/03/06 12:09

Q:
I am new to Perl, and am having a blast with it. However, I am at a
standstill. I get different results between running perl on the command
line and going through IIS (not ISAPI). The command line use acts as
expected. The IIS use runs, but, will not open files successfully:

A 15 line perl file, test.cgi, is as follows:

print "Contents-type: text/html","\n\n";
print "<html><body>\n";
print "Comparing FILE I/O through Perl
on command line and with IIS<br>\n";
if( open(FILE, '< test.dat')) {
print "true\n";
} else {
print "false\n";
}
@filedat=<FILE>;
close FILE;
$filesize=scalar(@filedat);
for ( $i=0 ; $i<$filesize ; $i++ ) {
print("$i:$filedat[$i]<br>\n");
}
print "</body></html>";

A 3 line data file, test.dat, is as follows:

This is a
test.
data, data, data...

If I run 'test.cgi' with perl on the command line, it produces the
expected result:

D:\Inetpub\cgi-bin\wiki>perl test.cgi
Contents-type: text/html

<html><body>
Comparing FILE I/O through Perl on command
line and with IIS<br>
true
0:This is a
<br>
1:test.
<br>
2:data, data, data...
<br>
</body></html>

When run test.cgi through the browser, it runs, but, the data file can't
be opened.
Result:

Comparing FILE I/O through Perl on command
line and with IIS
false

The OS is MsWin2k Pro v5.00.2195. The 'website' permissions for the
directory containing the two files are set for 'Read' and 'Script
Execution'.

I'm stumped. Any Ideas?
Thanks in advance.
*NAME-DELETED* *NAME-DELETED*

A:
Never use relative file names in a CGI script, like test.dat. Allways
specify the full path.

CGI standard does not define what the current working directory is.

Under IIS the current working directory is virtual directory root, in cour
case D:\Inetpub\cgi-bin and the program it starts wiki\test.cgi

Under Apache assuming the same configuration it would be
D:\Inetpub\cgi-bin\wiki

Under Netscape web server the current working directory (on UNIX) is where
the system manager started the server. Usually /

Thus specify the full path name.

Regards,
Peter

[ back to toc ]