Cant open a file with just a relative path

Discussion in 'Perl Misc' started by skieros, Apr 24, 2007.

  1. skieros

    skieros Guest

    open(FILE, ">>/somefolder/somesubfolder/digest.passwd") or die $!;
    print FILE "$user:$realm:" . Digest::MD5::md5_hex("$user:$realm:
    $pass") . "\n";
    close(FILE);

    Wehn i try to use this relative path instead of d:\www\blabla which is
    absolute apache tells me it cant find the file.

    Why i dotn sue an absolute path then? Because the same script will run
    both on localhost and remote server and the paths are not the same, so
    i need a relative path in order to work.

    I could use the $ENV{'SERVER_NAME'} to determine in which host the
    script runs and then set an appropriate path variable but i wan to
    avoid that by using a relatiev path.
     
    skieros, Apr 24, 2007
    #1
    1. Advertising

  2. skieros <> wrote:
    > open(FILE, ">>/somefolder/somesubfolder/digest.passwd") or die $!;

    ^
    ^ lose this char, or put a dot in front of it

    > Wehn i try to use this relative path



    relative paths do not start with a directory separator character.

    They are relative to the current directory, hence the "relative"
    in "relative path".


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Apr 25, 2007
    #2
    1. Advertising

  3. >>>>> "skieros" == skieros <> writes:

    skieros> open(FILE, ">>/somefolder/somesubfolder/digest.passwd") or die $!;
    skieros> print FILE "$user:$realm:" . Digest::MD5::md5_hex("$user:$realm:
    skieros> $pass") . "\n";
    skieros> close(FILE);

    skieros> Wehn i try to use this relative path instead of d:\www\blabla which is
    skieros> absolute apache tells me it cant find the file.

    This question was asked and answered on perlmonks. Please don't
    repeat the same thread here.

    And I find it annoying that someone posts the same question to multiple help
    forums without disclosing such. It causes an unneeded waste of resources.

    But, we'll always have newbies, I guess.

    print "Just another Perl hacker,"; # the original

    --
    Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
    <> <URL:http://www.stonehenge.com/merlyn/>
    Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
    See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

    --
    Posted via a free Usenet account from http://www.teranews.com
     
    Randal L. Schwartz, Apr 25, 2007
    #3
  4. skieros

    skieros Guest

    On Apr 25, 5:57 am, Tad McClellan <> wrote:
    > skieros <> wrote:


    > > Wehn i try to use this relative path

    >
    > relative paths do not start with a directory separator character.
    >
    > They are relative to the current directory, hence the "relative"
    > in "relative path".


    Yes my bad.

    i was trying to mention this
    open(FILE, ">>somefolder/somesubfolder/digest.passwd") or die $!;

    which is a relative path but still wont open th file.
     
    skieros, Apr 27, 2007
    #4
  5. skieros

    skieros Guest

    On Apr 25, 12:50 pm, (Randal L. Schwartz) wrote:

    > This question was asked and answered on perlmonks. Please don't
    > repeat the same thread here.
    >
    > And I find it annoying that someone posts the same question to multiple help
    > forums without disclosing such. It causes an unneeded waste of resources.


    yes, Iam sorry, as i explained to pesonal mail i couldnt see those 2
    thread on gougle groups up until today...dont know why....thats also
    why i posted 2 times.
     
    skieros, Apr 27, 2007
    #5
  6. skieros

    J. Gleixner Guest

    skieros wrote:
    > On Apr 25, 5:57 am, Tad McClellan <> wrote:
    >> skieros <> wrote:

    >
    >>> Wehn i try to use this relative path

    >> relative paths do not start with a directory separator character.
    >>
    >> They are relative to the current directory, hence the "relative"
    >> in "relative path".

    >
    > Yes my bad.
    >
    > i was trying to mention this
    > open(FILE, ">>somefolder/somesubfolder/digest.passwd") or die $!;
    >
    > which is a relative path but still wont open th file.


    Verify that the current working directory is actually what you think it
    should be.

    Does the directory "somefolder/somesubfolder" exist, in the current
    working directory?

    Does the user running the Web server have permissions to get to that
    directory?

    Does the user running the Web server have permissions to write to that
    directory?

    Is the file writable by the user running the Web server?
     
    J. Gleixner, Apr 27, 2007
    #6
  7. skieros

    skieros Guest

    On Apr 27, 7:50 pm, "J. Gleixner" <>
    wrote:
    > skieros wrote:
    > > On Apr 25, 5:57 am, Tad McClellan <> wrote:
    > >> skieros <> wrote:

    >
    > >>> Wehn i try to use this relative path
    > >> relative paths do not start with a directory separator character.

    >
    > >> They are relative to the current directory, hence the "relative"
    > >> in "relative path".

    >
    > > Yes my bad.

    >
    > > i was trying to mention this
    > > open(FILE, ">>somefolder/somesubfolder/digest.passwd") or die $!;

    >
    > > which is a relative path but still wont open th file.

    >
    > Verify that the current working directory is actually what you think it
    > should be.
    >
    > Does the directory "somefolder/somesubfolder" exist, in the current
    > working directory?
    >
    > Does the user running the Web server have permissions to get to that
    > directory?
    >
    > Does the user running the Web server have permissions to write to that
    > directory?
    >
    > Is the file writable by the user running the Web server?


    Wait isnt that user you describing Apache itself?!
     
    skieros, Apr 27, 2007
    #7
  8. skieros

    skieros Guest

    On Apr 27, 8:18 pm, Jim Gibson <> wrote:
    > In article <>,
    >
    >
    >
    > skieros <> wrote:
    > > On Apr 25, 5:57 am, Tad McClellan <> wrote:
    > > > skieros <> wrote:

    >
    > > > > Wehn i try to use this relative path

    >
    > > > relative paths do not start with a directory separator character.

    >
    > > > They are relative to the current directory, hence the "relative"
    > > > in "relative path".

    >
    > > Yes my bad.

    >
    > > i was trying to mention this
    > > open(FILE, ">>somefolder/somesubfolder/digest.passwd") or die $!;

    >
    > > which is a relative path but still wont open th file.

    >
    > Use the getcwd() function of the core Cwd module to determine your
    > default directory:
    >
    > use Cwd;
    > my $cwd = getcwd();
    > print "current directory: $cwd\n";
    >
    > Use the file text operators -e and -r to see if the file exists and is
    > readable by your process.
    >
    > Use stat to determine the file permissions of the file in question:
    >
    > my $file = '.../digest.passwd';
    > my @filestat = stat $file;
    > printf "Mode: %o\n", $filestat[2];
    >
    > Print the variables $> and $< to display your effective and real user
    > IDs.
    >
    > Good luck!


    Thank you i wa having that question myself.

    Iam on WinXP so do i ahve permission here like i do in linux?

    And if so how can i chmod 755 <FILE_IN_QUESTION> on this OS?
     
    skieros, Apr 27, 2007
    #8
  9. skieros

    skieros Guest

    On Apr 27, 8:18 pm, Jim Gibson <> wrote:
    > In article <>,
    >
    >
    >
    > skieros <> wrote:
    > > On Apr 25, 5:57 am, Tad McClellan <> wrote:
    > > > skieros <> wrote:

    >
    > > > > Wehn i try to use this relative path

    >
    > > > relative paths do not start with a directory separator character.

    >
    > > > They are relative to the current directory, hence the "relative"
    > > > in "relative path".

    >
    > > Yes my bad.

    >
    > > i was trying to mention this
    > > open(FILE, ">>somefolder/somesubfolder/digest.passwd") or die $!;

    >
    > > which is a relative path but still wont open th file.

    >
    > Use the getcwd() function of the core Cwd module to determine your
    > default directory:
    >
    > use Cwd;
    > my $cwd = getcwd();
    > print "current directory: $cwd\n";
    >
    > Use the file text operators -e and -r to see if the file exists and is
    > readable by your process.
    >
    > Use stat to determine the file permissions of the file in question:
    >
    > my $file = '.../digest.passwd';
    > my @filestat = stat $file;
    > printf "Mode: %o\n", $filestat[2];
    >
    > Print the variables $> and $< to display your effective and real user
    > IDs.
    >
    > Good luck!
    >
    > --
    > Jim Gibson
    >
    > Posted Via Usenet.com Premium Usenet Newsgroup Services
    > ----------------------------------------------------------
    > ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
    > ----------------------------------------------------------
    > http://www.usenet.com


    my $file = ">>$ENV{'DOCUMENT_ROOT'}/blabla/blabla/digest.passwd";
    my @filestat = stat $file;
    printf "Mode: %o\n", $filestat[0], $filestat[1], $filestat[2];

    returns mode 0; #dont knwo what is mode 0 though....
     
    skieros, Apr 27, 2007
    #9
  10. skieros

    J. Gleixner Guest

    skieros wrote:
    > On Apr 27, 8:18 pm, Jim Gibson <> wrote:

    [...]
    > my $file = ">>$ENV{'DOCUMENT_ROOT'}/blabla/blabla/digest.passwd";
    > my @filestat = stat $file;
    > printf "Mode: %o\n", $filestat[0], $filestat[1], $filestat[2];
    >
    > returns mode 0; #dont knwo what is mode 0 though....


    To learn about the stat call:

    perldoc -f stat

    my $file = "$ENV{'DOCUMENT_ROOT'}/blabla/blabla/digest.passwd";
     
    J. Gleixner, Apr 27, 2007
    #10
  11. skieros

    J. Gleixner Guest

    skieros wrote:
    > On Apr 27, 7:50 pm, "J. Gleixner" <>
    > wrote:


    >> Verify that the current working directory is actually what you think it
    >> should be.
    >>
    >> Does the directory "somefolder/somesubfolder" exist, in the current
    >> working directory?
    >>
    >> Does the user running the Web server have permissions to get to that
    >> directory?
    >>
    >> Does the user running the Web server have permissions to write to that
    >> directory?
    >>
    >> Is the file writable by the user running the Web server?

    >
    > Wait isnt that user you describing Apache itself?!


    Wait, you didn't answer the other questions. :)

    Maybe this will help with the user related questions:
    http://httpd.apache.org/docs/2.0/platform/windows.html

    Using stat will help show those permissions.
     
    J. Gleixner, Apr 27, 2007
    #11
  12. skieros

    skieros Guest

    On Apr 27, 10:28 pm, "J. Gleixner" <glex_no-s...@qwest-spam-
    no.invalid> wrote:
    > Using stat will help show those permissions.


    Iam gettign Mode 0 when i try to printout the results of stat that
    filled the array.
     
    skieros, Apr 27, 2007
    #12
  13. skieros

    Nikos Guest

    On Apr 29, 9:07 pm, Michele Dondi <> wrote:
    > On 27 Apr 2007 04:26:58 -0700, skieros <> wrote:
    >
    > >> And I find it annoying that someone posts the same question to multiple help
    > >> forums without disclosing such. It causes an unneeded waste of resources.

    >
    > >yes, Iam sorry, as i explained to pesonal mail i couldnt see those 2
    > >thread on gougle groups up until today...dont know why....thats also
    > >why i posted 2 times.

    >
    > This is a non sequitur: what did prevent you from writing something
    > along the lines of
    >
    > : Also posted in PerlMonks at
    > :
    > :http://perlmonks.org/?node_id=611837
    >
    > in the first place?


    actually posdte here first but couldne see my posts for several
    days....
     
    Nikos, Apr 30, 2007
    #13
  14. skieros

    Nikos Guest

    On Apr 30, 5:25 pm, Michele Dondi <> wrote:

    > Now, that's strange. Personally, I don't trust you. You post from GG,
    > don't you? Well, that's a real PITA, but all the times I've *had* to,
    > it either didn't work altogether or messages did appear quite soon at
    > least in their archive. Then the usual caveat about USENET articles
    > propagation applies. Even in this case, in PM you may have written:
    > "also posted in clpmisc, but the message doesn't seem to appear, will
    > post a reference soon."


    You may dont trust me but thats the truth, i seen my 2 posts days
    later in GG.
    >From now and on i'll post either here or imore preferably on

    Perlmonks which i get more efficient answers.
     
    Nikos, Apr 30, 2007
    #14
  15. On 30 Apr 2007 07:54:32 -0700, Nikos <> wrote:

    >>From now and on i'll post either here or imore preferably on

    >Perlmonks which i get more efficient answers.


    FWIW I choose where to post depending on the subject. OT posts are
    discouraged in both places. But as a rough observation, ones that have
    much to do with web server configuration or similar things, and very
    little to do with Perl are better tolerated there, probably due to the
    fact that it is a *web* based forum.


    Michele
    --
    {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
     
    Michele Dondi, May 2, 2007
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    3
    Views:
    19,577
    Sudsy
    Jul 8, 2004
  2. Thomas Guettler
    Replies:
    3
    Views:
    765
    Andrei
    Oct 27, 2003
  3. Nagaraj
    Replies:
    1
    Views:
    881
    Lionel B
    Mar 1, 2007
  4. Oren
    Replies:
    1
    Views:
    554
    Michael D. Ober
    Apr 29, 2007
  5. Shekar Ls
    Replies:
    3
    Views:
    160
    Brian Candler
    Aug 19, 2009
Loading...

Share This Page