M
Mad Scientist Jr
I am having trouble running some active perl in IIS5 under Win XP Pro.
I have activeperl installed, and perlscript is running - I got a
perlscript asp page to read a textbox from a form and do some simple
string comparisons, but am having trouble reading & writing files.
I have a file c:\inetpub\wwwroot\perl_read_file.txt that contains the
following text:
<h1>success</h1>
<p>read the file</p>
the script attempts to read.
The script also attemps to write to a file "perl_write_file.txt" in
wwwroot
The script is saved in c:\inetpub\wwwroot\perl_read_file.asp
and accessed at http://localhost/perl_read_file.asp
First I thought it might be permissions, but I have given the system
user ASP.NET full permissions to my c:\inetpub\wwwroot directory.
Unless there is some other user that the active perl stuff uses?
Here is the code (you will see many versions commented out, I have
tried different approaches)
Any help appreciated
<%@Language=PerlScript%>
<%
#
-----------------------------------------------------------------------------
# SET DEFAULTS
$sPage = "perl_read_file.asp";
#
-----------------------------------------------------------------------------
# GET VARIALBES FROM FORM
my($sFile) = $Request->Form('txtFile')->Item();
#
-----------------------------------------------------------------------------
# TEST FOR INPUT
if ($sFile eq '')
{
$sMessage = "Please type a file name and click [Submit].";
$sDefault = "perl_read_file.txt";
}
else
{
# $sMessage = "READ FILE: <br>";
#
# while ($myFile = <$sFile>)
# {
# open (FILE_IN, "$myFile") ;
# while ( $sNextLine=<FILE_IN> ) # read file one line at a time,
until end
# {
# $sMessage = join $sMessage, "\n", $sNextLine;
# }
# close (FILE_IN);
# }
#
# #my $filename = $Server->MapPath('/$sFile');
# $filename = $Server->MapPath('/$sFile');
#
# open (MYFILE, '$filename');
# while (<MYFILE>)
# {
# chomp;
# #print "$_\n";
# $sMessage = join $sMessage, $_, "\n";
# }
# close (MYFILE);
#
# #open( FILE, $Server->MapPath('/scripts/forum.asp') );
# #$sFile = join $Server->MapPath('/$sPage'), $sFile
# #$sFile = $Server->MapPath('$sPage')
#
# $sDefault = "$sFile";
# my $path = $Server->MapPath($Request->ServerVariables('PATH_INFO'));
# $sMessage = join $sMessage, "\n", $spath;
#my $path = $Server->MapPath($Request->ServerVariables('PATH_INFO'));
my $path = $Server->MapPath($sFile);
#$sMessage = $path;
open (MYFILE, '$path');
while (<MYFILE>)
{
chomp;
#$sMessage = join $sMessage, $_, "\n";
$sMessage = $sMessage . "x";
}
close (MYFILE);
} # else
#
-----------------------------------------------------------------------------
# WRITE A FILE
my $path = $Server->MapPath('perl_write_file.txt');
open (MYFILE, '>>$path');
print MYFILE "user requested $sFile\n";
close (MYFILE);
#
-----------------------------------------------------------------------------
# ENCODE OUTPUT
#$sMessage = $Server->HTMLEncode($sMessage);
%>
<HTML>
<TITLE>PerlScript Test Read File</TITLE>
<BODY>
<FORM ACTION="<% $Response->Write("$sPage"); %>" METHOD="POST">
<P>
<% $Response->Write("$sMessage"); %>
</P>
<TABLE>
<TR>
<TD align="right">File:</TD>
<TD align="left">
<INPUT NAME="txtFile" VALUE="<% $Response->Write("$sDefault");
%>">
<INPUT TYPE="SUBMIT" VALUE="Submit">
</TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
I have activeperl installed, and perlscript is running - I got a
perlscript asp page to read a textbox from a form and do some simple
string comparisons, but am having trouble reading & writing files.
I have a file c:\inetpub\wwwroot\perl_read_file.txt that contains the
following text:
<h1>success</h1>
<p>read the file</p>
the script attempts to read.
The script also attemps to write to a file "perl_write_file.txt" in
wwwroot
The script is saved in c:\inetpub\wwwroot\perl_read_file.asp
and accessed at http://localhost/perl_read_file.asp
First I thought it might be permissions, but I have given the system
user ASP.NET full permissions to my c:\inetpub\wwwroot directory.
Unless there is some other user that the active perl stuff uses?
Here is the code (you will see many versions commented out, I have
tried different approaches)
Any help appreciated
<%@Language=PerlScript%>
<%
#
-----------------------------------------------------------------------------
# SET DEFAULTS
$sPage = "perl_read_file.asp";
#
-----------------------------------------------------------------------------
# GET VARIALBES FROM FORM
my($sFile) = $Request->Form('txtFile')->Item();
#
-----------------------------------------------------------------------------
# TEST FOR INPUT
if ($sFile eq '')
{
$sMessage = "Please type a file name and click [Submit].";
$sDefault = "perl_read_file.txt";
}
else
{
# $sMessage = "READ FILE: <br>";
#
# while ($myFile = <$sFile>)
# {
# open (FILE_IN, "$myFile") ;
# while ( $sNextLine=<FILE_IN> ) # read file one line at a time,
until end
# {
# $sMessage = join $sMessage, "\n", $sNextLine;
# }
# close (FILE_IN);
# }
#
# #my $filename = $Server->MapPath('/$sFile');
# $filename = $Server->MapPath('/$sFile');
#
# open (MYFILE, '$filename');
# while (<MYFILE>)
# {
# chomp;
# #print "$_\n";
# $sMessage = join $sMessage, $_, "\n";
# }
# close (MYFILE);
#
# #open( FILE, $Server->MapPath('/scripts/forum.asp') );
# #$sFile = join $Server->MapPath('/$sPage'), $sFile
# #$sFile = $Server->MapPath('$sPage')
#
# $sDefault = "$sFile";
# my $path = $Server->MapPath($Request->ServerVariables('PATH_INFO'));
# $sMessage = join $sMessage, "\n", $spath;
#my $path = $Server->MapPath($Request->ServerVariables('PATH_INFO'));
my $path = $Server->MapPath($sFile);
#$sMessage = $path;
open (MYFILE, '$path');
while (<MYFILE>)
{
chomp;
#$sMessage = join $sMessage, $_, "\n";
$sMessage = $sMessage . "x";
}
close (MYFILE);
} # else
#
-----------------------------------------------------------------------------
# WRITE A FILE
my $path = $Server->MapPath('perl_write_file.txt');
open (MYFILE, '>>$path');
print MYFILE "user requested $sFile\n";
close (MYFILE);
#
-----------------------------------------------------------------------------
# ENCODE OUTPUT
#$sMessage = $Server->HTMLEncode($sMessage);
%>
<HTML>
<TITLE>PerlScript Test Read File</TITLE>
<BODY>
<FORM ACTION="<% $Response->Write("$sPage"); %>" METHOD="POST">
<P>
<% $Response->Write("$sMessage"); %>
</P>
<TABLE>
<TR>
<TD align="right">File:</TD>
<TD align="left">
<INPUT NAME="txtFile" VALUE="<% $Response->Write("$sDefault");
%>">
<INPUT TYPE="SUBMIT" VALUE="Submit">
</TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>