Problem writing to a file from a perl website

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bpejman
    New Member
    • Oct 2007
    • 6

    Problem writing to a file from a perl website

    I have a Perl-driven website on a windows 2003 server. I have configured the IIS and have set the permissions on the Home Directory tab to Read, Write and my Execute Permissions are set to "Scripts and Executable."

    I have gotten the site to work but my problem is, when I run the below code from my web browser, I do not see a file called "data.txt" in the same directory. When I execute this from the console, it works just fine. What am I doing wrong?? Is there anything else that I need to set?

    Any help would be appreciated!

    Code:
    use strict;
    open (MYFILE, '>>data.txt');
    print MYFILE "this is a test\n";
    close (MYFILE);
    
    print "HTTP/1.0 200 OK\n";
    print "Content-Type: text/html\n\n\n";
    print <<html_end;
    <html>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-88959-1">
    </head>
    <body>
    <p>Writing to a file...complete</p>
    </body>
    </html>
    html_end
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Originally posted by bpejman
    I have a Perl-driven website on a windows 2003 server. I have configured the IIS and have set the permissions on the Home Directory tab to Read, Write and my Execute Permissions are set to "Scripts and Executable."

    I have gotten the site to work but my problem is, when I run the below code from my web browser, I do not see a file called "data.txt" in the same directory. When I execute this from the console, it works just fine. What am I doing wrong?? Is there anything else that I need to set?

    Any help would be appreciated!

    Code:
    use strict;
    open (MYFILE, '>>data.txt');
    print MYFILE "this is a test\n";
    close (MYFILE);
    
    print "HTTP/1.0 200 OK\n";
    print "Content-Type: text/html\n\n\n";
    print <<html_end;
    <html>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-88959-1">
    </head>
    <body>
    <p>Writing to a file...complete</p>
    </body>
    </html>
    html_end
    have you checked the cgi-bin directory where this script is most likely residing? Also, after the opening of the file, test to make sure it worked.

    [code=perl]
    open (MYFILE, '>>data.txt') or die "Cannot open file: $!";
    [/code]

    That way, it gives you the error if it has a problem.

    So that you are able to see the errors, also add the following:

    [code=perl]
    use CGI::Carp qw(fatalsToBrow ser);
    [/code]

    Comment

    • bpejman
      New Member
      • Oct 2007
      • 6

      #3
      Thank you so much for replying. My script does not reside under cgi-bin. It's actually under wwwroot folder. I do know that the script does get executed but as I suspected, I'm running into permission issues.

      I did what you mentioned, by the way, thanks for that! and added
      Code:
      CGI::Carp qw(fatalsToBrowser);
      and surely it came back saying "Cannot Open file...Permissi on denied"

      I don't believe I would need to set the permissions on the NTFS side. Even though I did and still did not resolve my problem. Maybe I need to stop and start the webserver for the permissions to kick in???

      Not sure what to do

      Originally posted by numberwhun
      have you checked the cgi-bin directory where this script is most likely residing? Also, after the opening of the file, test to make sure it worked.

      [code=perl]
      open (MYFILE, '>>data.txt') or die "Cannot open file: $!";
      [/code]

      That way, it gives you the error if it has a problem.

      So that you are able to see the errors, also add the following:

      [code=perl]
      use CGI::Carp qw(fatalsToBrow ser);
      [/code]

      Comment

      • bpejman
        New Member
        • Oct 2007
        • 6

        #4
        Ok, I figured it out. I set the directory permissions on the wwwroot and Inetpub to Write and it worked. The directory permissions were inherited which never really made it up to the directory that I had my script in. Now it all works!

        :)

        Originally posted by bpejman
        Thank you so much for replying. My script does not reside under cgi-bin. It's actually under wwwroot folder. I do know that the script does get executed but as I suspected, I'm running into permission issues.

        I did what you mentioned, by the way, thanks for that! and added
        Code:
        CGI::Carp qw(fatalsToBrowser);
        and surely it came back saying "Cannot Open file...Permissi on denied"

        I don't believe I would need to set the permissions on the NTFS side. Even though I did and still did not resolve my problem. Maybe I need to stop and start the webserver for the permissions to kick in???

        Not sure what to do

        Comment

        Working...