How do I find my runtime directory?

J

Joe Cosby

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)
 
J

Joe Cosby

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
 
J

Jürgen Exner

Joe said:
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

Joe Cosby

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


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.
 
G

Gunnar Hjalmarsson

Joe said:
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.
 
J

Jürgen Exner

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

Joe Cosby

foreach $reply (@responses)

thanks

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,165
Latest member
JavierBrak
Top