ASP / PerlScript and read and write to files?

R

roger_owen333

In ASP using PerlScript how do I read and write to files?

I tried:

my $File = $Server->CreateObject("Scripting.FileSystemObject");

my $a = $File->CreateTextFile("c:\\testfile.txt", true);

but the following two lines cause an error???

$a->WriteLine("This is a test.");

$a->Close();

In ASP using JavaScript the following works:

// JScript

var fso = new ActiveXObject("Scripting.FileSystemObject");

var a = fso.CreateTextFile("c:\\testfile.txt", true);

a.WriteLine("This is a test.");

a.Close();
 
X

xhoster

In ASP using PerlScript how do I read and write to files?

I tried:

my $File = $Server->CreateObject("Scripting.FileSystemObject");

my $a = $File->CreateTextFile("c:\\testfile.txt", true);

but the following two lines cause an error???

$a->WriteLine("This is a test.");

$a->Close();

If PerlScript is something like Perl, then I would try:

print $a "This is a test.";
close $a;

Xho
 
M

Matt Garrish

In ASP using PerlScript how do I read and write to files?

I tried:

my $File = $Server->CreateObject("Scripting.FileSystemObject");

my $a = $File->CreateTextFile("c:\\testfile.txt", true);

but the following two lines cause an error???

$a->WriteLine("This is a test.");

$a->Close();

It would seem that you're not getting a valid textfile object back. I can't
reproduce this problem on IIS 5 on XP Pro using ActivePerl Build 813,
though, so I have no clue why. PerlScript can be very flaky depending on the
platform and version. I'm assuming that the IUSR has write permissions to
the root of your c:\ drive, if it works in jscript (though I can't imagine
that's a good thing).

Don't feel you have to jump through asp's hoops to get anything done. The
following will work just as easily:

open(my $fh, '>', 'c:/testfile.txt') or die $!;
print $fh "some text\n";
close($fh);

If nothing else, it should make it pretty clear whether the script can write
to the root.

Matt
 
R

roger_owen333

It would appear after much researching that ASP using PerlScript can
not write to or read from files so I decided to use JavaScript using
ActiveX Objects that does not require ASP. It is possible to read and
write to files with an HTML page using JavaScript alone. This is what I
tried:

<HTML>
<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!--

var fso = new ActiveXObject("Scripting.FileSystemObject");
var file = fso.CreateTextFile("c:\\new.txt", true);
file.Write("This is a test.");
file.Write("This is a test.");
file.Write("This is a test.*\n");
file.Write("This is a test.");
file.Write("This is a test.");
file.Write("This is a test.*\n");
file.Close();

var line;

var ForReading = 1;

file = fso_OpenTextFile("c:\\new.txt", ForReading);

while ( !file.AtEndOfStream ){

line = file.ReadLine();

document.write(line);

}

file.Close();

-->
</SCRIPT>

</HEAD>
<BODY>
Testing 123...

</BODY>
</HTML>
 
M

Matt Garrish

It would appear after much researching that ASP using PerlScript can
not write to or read from files so I decided to use JavaScript using
ActiveX Objects that does not require ASP. It is possible to read and
write to files with an HTML page using JavaScript alone. This is what I
tried:

That's a silly conclusion. Would you care to point to where you discovered
this fact? I already told you I have no problem writing to a file using
either the asp method you supplied or perl's built-in method, so I have to
wonder what magic is in my computer. No one can debug your application for
you without any help.

And good luck getting your program to read/write files on the client side. I
can tell you that's not going far. If you were trying to write to the
client's machine using PerlScript, then it's not surprising you failed. If
you could write any code you wanted and have it executed on any client's
machine with perl installed the internet wouldn't be a very fun place. No
browser-based scripting language allows that kind of interaction with the
file system by default. And if you think people are going to allow your
activex controls as written in your javascript, I think you should
reconsider your logic.

Matt
 
R

roger_owen333

Actually, I only need to read/write from the client side on one machine
but I have not been able to find any documentation on how to use
ActiveX Objects with Perl in an ASP using IIS???
 
M

Matt Garrish

Actually, I only need to read/write from the client side on one machine
but I have not been able to find any documentation on how to use
ActiveX Objects with Perl in an ASP using IIS???

Have you had a look at:

http://aspn.activestate.com/ASPN/docs/ActivePerl/5.8/Components/Windows/PerlScript.html

My (perhaps dated now) understanding has been that the only way to read or
write on the client side is if you sign your activex controls. ASP runs on
the server, and you have much more freedom there, which is why you may want
to reconsider the necessity of saving a file to the client machine.

Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top