Home > Archive > PERL CGI Beginners > January 2006 > Problems opening files from CGI.pm program in Windows
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Problems opening files from CGI.pm program in Windows
|
|
| Mary Anderson 2006-01-22, 6:56 pm |
|
Hi All,
I am running Perl 5.8.7 (ActivePerl) on a Windows XP platform. I have
been unable to open files from a CGI.pm script. Here is the offending code:
use CGI qw/:standard :html3 :netscape/;
use POSIX 'strftime';
use CGI::Carp('carpout');
open(LOG,">>.\guestbook.err")||
die "couldn't open log. $!";
Here is the error message:
guestbook.pl: couldn't open log. Permission denied at
c:\inetpub\wwwroot\cgi-bin\guestbook.pl line 5
I have tried full path names with forward and backwards slashes. Sigh, if
only I were in UNIX, the error message would be sensible and useful!
The same piece of code works ok in a .pl script without CGI.
Any help is appreciated!
Mary Anderson
| |
| Paul Archer 2006-01-22, 9:55 pm |
| 3:43pm, Mary Anderson wrote:
>
> Hi All,
>
> I am running Perl 5.8.7 (ActivePerl) on a Windows XP platform. I have
> been unable to open files from a CGI.pm script. Here is the offending code:
>
>
> use CGI qw/:standard :html3 :netscape/;
> use POSIX 'strftime';
> use CGI::Carp('carpout');
> open(LOG,">>.\guestbook.err")||
> die "couldn't open log. $!";
>
> Here is the error message:
>
> guestbook.pl: couldn't open log. Permission denied at
^^^^^^^^^^^^^^^^^
> c:\inetpub\wwwroot\cgi-bin\guestbook.pl line 5
>
> I have tried full path names with forward and backwards slashes. Sigh, if
> only I were in UNIX, the error message would be sensible and useful!
>
It looks like the error message is sensible and useful. While we Unix folk
tend to forget, Windows does have a mechanism for file permissions, and
that's exactly what your script is complaining about. This is the #1 common
problem with CGI scripts: the web server runs as an unpriviledged user that
can't read or write some file that the developer, when running the script
from the command line, can.
> The same piece of code works ok in a .pl script without CGI.
>
> Any help is appreciated!
>
> Mary Anderson
>
> --
> To unsubscribe, e-mail: beginners-cgi-unsubscribe@perl.org
> For additional commands, e-mail: beginners-cgi-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
--------------------------------------------------------------
"Football is a mistake. It combines the two worst elements of
American life: violence and committee meetings." --George Will
--------------------------------------------------------------
| |
| Bob Showalter 2006-01-22, 9:55 pm |
| Mary Anderson wrote:
> Hi All,
>
> I am running Perl 5.8.7 (ActivePerl) on a Windows XP platform. I have
> been unable to open files from a CGI.pm script. Here is the offending code:
>
>
> use CGI qw/:standard :html3 :netscape/;
> use POSIX 'strftime';
> use CGI::Carp('carpout');
> open(LOG,">>.\guestbook.err")||
> die "couldn't open log. $!";
First, to represent a backslash inside double quotes, you need to
specify it as two backslashes:
".\\guestbook.err"
Second, I would recommend that you never make assumptions about what the
current directory is from within a CGI script. Always use full path names.
>
> Here is the error message:
>
> guestbook.pl: couldn't open log. Permission denied at
> c:\inetpub\wwwroot\cgi-bin\guestbook.pl line 5
>
> I have tried full path names with forward and backwards slashes. Sigh, if
> only I were in UNIX, the error message would be sensible and useful!
You would get the same message in Unix. The directory you're trying to
write to is not writeable by the webserver process, or the log file
exists, and is not writeable by the webserver process.
>
> The same piece of code works ok in a .pl script without CGI.
Typically because the users are different.
| |
| Dr.Ruud 2006-01-23, 7:55 am |
| Mary Anderson:
> open(LOG,">>.\guestbook.err")||
Simply try '>>./guestbook.err'.
BTW, whitepace is cheap nowadays:
my $logfile = './guestbook.err';
open( LOG, '>>', $logfile )
or die "Couldn't open log ($logfile) $!";
--
Grtz, Ruud
| |
| Jim Riddles 2006-01-24, 6:55 pm |
| Mary,
This appears to be a simple permissions error. When running a cgi script you are running with the web server's credentials, so your log file is not writeable by that user. When run locally, you are using the credentials that you are logged on as, so the script has access. This is no different from Unix/Linux.
Change the permissions on the file to allow access by your web server. The user is usually IUSER_HOSTNAME. Substitute HOSTNAME with your server's host name. Give that user read/write permissions on "guestbook.err."
James M Riddles
IT Technician
White Oak Printing
1180 Dillerville Road
Lancaster, PA 17601
Ph: (717) 291-2222 Ext. 228
Fax: (717) 291-5678
|
|
|
|
|