问题描述:

I have a problem that I have tried to get to work. First, I wrote a PERL Script a long time ago and it is on another server. We are creating a new server, and I have downloaded/installed Strawberry PERL 64-bit. I am now checking all of my PERL scripts to make sure all work on the new server.

I converted a script to the new way Strawberry wants (use of require to use another file in-line), but I just can't get past the following error: permission denied to open file for writing.

I start will a shell program that calls the inline file:

require "cgi/cr/main_test.pl";

This array hold the text files that will be run through:

my @main = ("BOOKS","CDs","DVDs","VIDEOS","PERIODICALS","VIDEO-GAMES","TOYS","RECORDED-BOOKS","BINS");

The require calls a program to open files for writing results, and then goes through each text file and display and add the numbers in each file.

#!/usr/bin/perl -w

my $recFnd = "C:\\inetpub\\wwwroot\\cgi-bin\\CustomerRelations\\recs_found.txt";

chmod 0755, $recFnd;

print "<p>$recFnd</p>";

open (my $newloc, '>', $recFnd) or die "Couldn't open: $!";

The above is $recFnd opens a text file that will be written any code that is found (I have a file that has all of the codes. I use the data from both to find any new codes that have been used.). One the next line I change file permission, but that is just passed by (may work, but I cannot test since this is a windows environment). Then I print the location 7 name of the file to be sure it has the correct file. Finally, the open where I have tried every version I could to get this to work. Originally the code for opening the file as:

open (NEWLOC, "> recs_found.txt ") || die;

No matter what I do, I get a permission error. The folder the files for writing is in has everyone in the building Full Control. I am not sure what I can do.

If anyone can help, it would be very appreciated.

网友答案:

So if this is Strawberry Perl, this is on Windows, and if these are scripts, they are probably running under a system account. Your problem is probably on the filesystem acls problem not on the Perl side.

The way to troubleshoot and resolve this issue is to art by verifying which user the service is running under. If this is a web application, it will be whatever service is running Apache, IIS, or the like. It is likely to be the NetworkService account. However, you should verify this. As with all things it is a good idea to give read permission to all parent directories and write access to this directory.

Note that Windows uses ACLs as a model rather than the UNIX UGW model.

If other scripts can write to the file from the web server then something else is happening, but I would be very surprised if it were.

Additionally, your post has a UNIX shebang line while your post indicates a Windows implementation. This is partly being pedantic, but solving these problems requires an eye for detail and so being pedantic here is good.

相关阅读:
Top