Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a problem that I could use some help with.
#!/usr/bin/perl -w use Win32::File; $counter_name="TEST SCRIPT"; $sample_file="sample.t"; print "Content-type:text/html\n\n"; print "<center><font size=1>Script Name: $counter_name</font><br><br> +<br>\n"; print "Attempt to write file: <b>$sample_file</b><br></center>\n"; print "\n\n"; open(FH, ">$sample_file") or die(print "Cannot write to $sample_file f +ile: $!\n"); print FH "I will print this to a file\n"; close(FH); print "<center><font size=1>Writing File $sample_file, complete - $co +unter_name</font><br><br><br></center>\n"; print "\n\n";
I keep getting PERMISSION DENIED error. File permissions are set for read and write the file is located in the cgi-bin.

20030309 Edit by Corion : Added CODE tags

Replies are listed 'Best First'.
Re: Perl and WINNT write problem
by BrowserUk (Patriarch) on Mar 09, 2003 at 01:50 UTC

    Try adding the following line to your script

    print $ENV{USERNAME};

    I'm betting that when your script is being run by the webserver, it is running as a different userid to when you run it at the command line and that the permissions on the file you are trying to write to are such that the userid used by the webserver does not have permission to write to it.


    Examine what is said, not who speaks.
    1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
    2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
    3) Any sufficiently advanced technology is indistinguishable from magic.
    Arthur C. Clarke.
Re: Perl and WINNT write problem
by meetraz (Hermit) on Mar 09, 2003 at 07:40 UTC
    CGI programs are run as the IUSR account by default, which has very little permissions. In order to have the CGI program create files, you would need to give the IUSR account "write" permissions to the directory where you want the file created.
Re: Perl and WINNT write problem
by Cabrion (Friar) on Mar 09, 2003 at 01:02 UTC
    Does the file exist where you think it does?

    Try doing this to see if it exists. Your current directory may not be what you expect.

    if (-e $sample_file) { ... }
      still same response as before.
Re: Perl and WINNT write problem
by Garion72 (Initiate) on Mar 09, 2003 at 03:52 UTC
    print "$ENV{USERNAME}";
    and
    $username=$ENV(USERNAME); ... print "$username"; ...
    shows nothing.

      That's strange, USERNAME in normally set. Try this: Noting that they are {}'s not ()'s.

      print "<H1>$_=$ENV{$_}</H1>\n" for key %ENV;

      A couple of things. You don't need to quote the variable names unless your using interpolation to format the value of the variable together with other stuff.

      You say that $username=$ENV(USERNAME); "shows nothing", which is strange, as that line has a syntax error. Have you checked the logs?

      You said this is running under NT4, but not which webserver? Is this a box you have administrative access to? Are you using it local or remotely?


      Examine what is said, not who speaks.
      1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
      2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
      3) Any sufficiently advanced technology is indistinguishable from magic.
      Arthur C. Clarke.
        print Win32::LoginName();

        On the IIS that ive used $ENV{USERNAME} isn't set for CGI scripts. The Win32 call works though.


        ---
        demerphq


Re: Perl and WINNT write problem
by Garion72 (Initiate) on Mar 09, 2003 at 23:40 UTC
    Thanks all for the help. Once I got a hold of the server admin and told him about IUSR he gave it a try.

    The IUSR permissions did the job!!

    As you can tell the original thread was posted by me before I signed up for username.