How do I find my runtime directory?

Discussion in 'Perl' started by Joe Cosby, Apr 4, 2004.

  1. Joe Cosby

    Joe Cosby Guest

    This seems like a simple thing, but I can't find anything in the "Perl
    Cookbook" or the online Perl docs to answer this.

    When a script runs from my host's server, the working directory
    doesn't appear to be the directory the script is located in. (They
    have Perl running under IIS, I don't know what versions).

    I tried File::Spec->curdir() , but it just returns ".", which is
    accurate, but not very helpful.

    Does anyone know a way to do this?

    --
    Joe Cosby
    http://joecosby.com/
    pablo picasso well, some people try to pick up girls and they get called an asshole.
    this never happened to pablo picasso. he could walk down your street and girls
    could not resist his stare and pablo picasso never got called an asshole. the girls
    would turn the colour of an avocado when he drove down their street in his eldorado.
    he could drive down your street and girls could not resist his stare. pablo picasso
    never got called the asshole. oh well be not schmuck, be not obnoxious, be not
    bell-bottom bummer or asshole. this is the story of pablo picasso. he could walk
    down your street and girls could not resist his stare, so pablo picasso never got
    called an asshole. not like you. (j.richman)
     
    Joe Cosby, Apr 4, 2004
    #1
    1. Advertising

  2. Joe Cosby

    Joe Cosby Guest

    On Sun, 04 Apr 2004 12:18:09 -0700, Joe Cosby
    <> wrote:

    >
    >This seems like a simple thing, but I can't find anything in the "Perl
    >Cookbook" or the online Perl docs to answer this.
    >
    >When a script runs from my host's server, the working directory
    >doesn't appear to be the directory the script is located in. (They
    >have Perl running under IIS, I don't know what versions).
    >
    >I tried File::Spec->curdir() , but it just returns ".", which is
    >accurate, but not very helpful.
    >
    >Does anyone know a way to do this?


    Maybe I should clarify what I'm trying to accomplish a little.

    I want to be have a relative directory structure within my code. For
    instance, within a "code" directoy I have scripts, then a subdirectory
    "templates" within "code" contains html templates.

    I want to be able to read the templates by loading a file
    "templates/templatename.htm", instead of having to hard-code
    "e:\www\joecosby\code\templates\templatename.htm" (the path on the
    server) in the code I upload, ""C:\My
    Documents\webpage\newstuff\code\templates\templatename.htm" (the path
    on my local machine) in the code before I upload it, etc.

    I mean it's the same idea as using relative references versus absolute
    references in HTML, it saves me from a huge amount of maintenance
    work.

    The perl environment seems to know what directory my script is running
    from, when I get error messages they include the complete path to the
    script, so if I could just chdir() to that directory at the start of
    all my scripts that would at least be a workable solution.

    --
    Joe Cosby
    http://joecosby.com/
    "Now that I've inspired a character in a Godzilla movie, all I
    really still desire is for several Ingmar Bergman characters to sit in a
    circle and read my reviews to one another in hushed tones." - Roger Ebert
     
    Joe Cosby, Apr 4, 2004
    #2
    1. Advertising

  3. Joe Cosby wrote:
    > When a script runs from my host's server, the working directory
    > doesn't appear to be the directory the script is located in.


    It would be a rare coincidence indeed if the script were located in the
    current working directory.

    > Does anyone know a way to do this?


    perldoc Cwd

    jue
     
    Jürgen Exner, Apr 5, 2004
    #3
  4. Joe Cosby

    Joe Cosby Guest

    On Mon, 05 Apr 2004 04:37:29 GMT, "Jürgen Exner"
    <> wrote:

    >Joe Cosby wrote:
    >> When a script runs from my host's server, the working directory
    >> doesn't appear to be the directory the script is located in.

    >
    >It would be a rare coincidence indeed if the script were located in the
    >current working directory.
    >
    >> Does anyone know a way to do this?

    >
    >perldoc Cwd
    >


    Thanks for the help; what I would like to be able to do though, if
    possible, would be to somehow determine the path where the script is
    located.

    I have a directory structure like this on the server:

    top page directory
    - Code (directory)
    ---- mail.pl

    That is, inside the top directory is a subdirectory "code", and inside
    that is "mail.pl".

    When mail.pl is called though, the working directory is the top
    directory. It would be useful, for a number of tasks, to be able to
    determine the location of the script within the code base.

    --
    Joe Cosby
    http://joecosby.com/
    0x29A - opcode of the beast!
     
    Joe Cosby, Apr 11, 2004
    #4
  5. Joe Cosby wrote:
    > what I would like to be able to do though, if possible, would be to
    > somehow determine the path where the script is located.


    You can use $0 or $ENV{SCRIPT_FILENAME} for that.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Apr 11, 2004
    #5
  6. Joe Cosby wrote:
    [...]
    > Thanks for the help; what I would like to be able to do though, if
    > possible, would be to somehow determine the path where the script is
    > located.


    perldoc FindBin

    jue
     
    Jürgen Exner, Apr 11, 2004
    #6
  7. Joe Cosby

    Joe Cosby Guest

    foreach $reply (@responses)

    thanks

    blrk. I'm making jokes in Perl. That's really not a good sign.

    --
    Joe Cosby
    http://joecosby.com/
    EMBRACE the SUCKINESS
     
    Joe Cosby, Apr 11, 2004
    #7
    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. =?Utf-8?B?QW5u?=
    Replies:
    0
    Views:
    526
    =?Utf-8?B?QW5u?=
    Jan 11, 2005
  2. Hal Vaughan
    Replies:
    11
    Views:
    1,198
    Gordon Beaton
    May 22, 2006
  3. Wybo Dekker
    Replies:
    1
    Views:
    399
    Yukihiro Matsumoto
    Nov 15, 2005
  4. vdvorkin
    Replies:
    0
    Views:
    440
    vdvorkin
    Feb 10, 2011
  5. vdvorkin
    Replies:
    3
    Views:
    870
    vdvorkin
    Feb 14, 2011
Loading...

Share This Page