Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

activestate opens files from commandline but not when executed as a cgi

by Anonymous Monk
on Jun 10, 2002 at 18:55 UTC ( [id://173257]=perlquestion: print w/replies, xml ) Need Help??

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

I have activestate perl installed on a w2k server running iis. Scripts run from the commandline open files without difficulty, but not when run as a cgi... comments?

Replies are listed 'Best First'.
Re: activestate opens files from commandline but not when executed as a cgi
by Ovid (Cardinal) on Jun 10, 2002 at 19:03 UTC

    Remember to add an "or die: $!" (or croak) after the open. That will write a useful message to the error log.

    my $file = 'somedir/somefile.dat'; open FILE, "< $file" or die "Cannot open $file for reading: $!";

    The problem is likely bad permissions. You run from the command line as a different set of permissions from the Web server. It's also possible that if you're running the file from a different location, your paths could be wrong and the system can't find the file specified.

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

      To elaborate, I am using absolute, not relative paths, I do have a die after the open, no message is printed. The server is running as LOCAL_USER, the file permissions are set such that any user has full privileges on the file its parent directories.
        Where are you looking for the error messages?

        Try
        use CGI::Carp qw(fatalsToBrowser);
        to see the error in the browser, or check the server error logs.

Re: activestate opens files from commandline but not when executed as a cgi
by dree (Monsignor) on Jun 10, 2002 at 19:20 UTC
    Are you using relative paths to read the file?

    IIS doesn't like relative paths... try absolute ones.
    For example, try:
    ($relative_path=$ENV{SCRIPT_NAME}) =~ s|[^/]+$||; $absolute_path=$ENV{PATH_TRANSLATED}.$relative_path; $filename=$absolute_path.'file.txt';
Re: activestate opens files from commandline but not when executed as a cgi
by feanor (Initiate) on Jun 10, 2002 at 21:34 UTC
    THE ANSWER IS: use single quotes, not double quotes in the open() statement.

    So:
    open(HEADER, 'D:\path\to\file\file.txt') || die ("$!"); This works!

    NOT: open(HEADER, "D:\path\to\file\file.txt") || die ("$!"); This doesn't work!
      or escape the slashes, of course

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://173257]
Approved by Ovid
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-03-19 05:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found