By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,278 Members | 1,566 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,278 IT Pros & Developers. It's quick & easy.

Problem writing to a file from a perl website

P: 6
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!

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. open (MYFILE, '>>data.txt');
  3. print MYFILE "this is a test\n";
  4. close (MYFILE);
  5.  
  6. print "HTTP/1.0 200 OK\n";
  7. print "Content-Type: text/html\n\n\n";
  8. print <<html_end;
  9. <html>
  10. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  11. <html>
  12. <head>
  13. <meta http-equiv="Content-Type" content="text/html; charset=iso-88959-1">
  14. </head>
  15. <body>
  16. <p>Writing to a file...complete</p>
  17. </body>
  18. </html>
  19. html_end
  20.  
Feb 15 '08 #1
Share this Question
Share on Google+
3 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
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!

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. open (MYFILE, '>>data.txt');
  3. print MYFILE "this is a test\n";
  4. close (MYFILE);
  5.  
  6. print "HTTP/1.0 200 OK\n";
  7. print "Content-Type: text/html\n\n\n";
  8. print <<html_end;
  9. <html>
  10. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  11. <html>
  12. <head>
  13. <meta http-equiv="Content-Type" content="text/html; charset=iso-88959-1">
  14. </head>
  15. <body>
  16. <p>Writing to a file...complete</p>
  17. </body>
  18. </html>
  19. html_end
  20.  
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.

Expand|Select|Wrap|Line Numbers
  1. open (MYFILE, '>>data.txt') or die "Cannot open file:  $!";
  2.  
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:

Expand|Select|Wrap|Line Numbers
  1. use CGI::Carp qw(fatalsToBrowser);
  2.  
Feb 15 '08 #2

P: 6
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
Expand|Select|Wrap|Line Numbers
  1. CGI::Carp qw(fatalsToBrowser);
and surely it came back saying "Cannot Open file...Permission 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

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.

Expand|Select|Wrap|Line Numbers
  1. open (MYFILE, '>>data.txt') or die "Cannot open file:  $!";
  2.  
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:

Expand|Select|Wrap|Line Numbers
  1. use CGI::Carp qw(fatalsToBrowser);
  2.  
Feb 15 '08 #3

P: 6
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!

:)

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
Expand|Select|Wrap|Line Numbers
  1. CGI::Carp qw(fatalsToBrowser);
and surely it came back saying "Cannot Open file...Permission 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
Feb 15 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.