punkish has asked for the wisdom of the Perl Monks concerning the following question:
I come again with another in a continuing line of questions -- How do I find the path of the script running as a Win service? I have the following scenario.
Here is what I have tried --
File::Spec->rel2abs(curdir()), $FindBin::Bin, Cwd->cwd() all suffer from the same problem thusly: the path returned is the ostensible path to the service, of the form "C:\Windows\System32", not "E:\programs\foo", the path to foo.exe that is being run as that darned service.
I finally implemented the following solution --
The above works, however, is there a less ugly solution?@path = split(/\\/, $0); pop(@path); $path = join('\\', @path);
I have a related question --
doesn't work for obvious reasons. However, neither doesBEGIN { my $foo = 'bar'; } print $foo;
Why? Does BEGIN have its own namespace? How can I declare something once (like the $path to the script I am trying to figure out above), and have it be picked up in the BEGIN block as well as in the rest of the script or any other module that I might use in the script?my $foo = 'bar'; BEGIN { print $foo; }
Many thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: finding the path of the script running as Win service
by borisz (Canon) on Jan 05, 2005 at 22:18 UTC | |
by punkish (Priest) on Jan 05, 2005 at 22:24 UTC | |
by davido (Cardinal) on Jan 05, 2005 at 22:47 UTC | |
by punkish (Priest) on Jan 05, 2005 at 22:55 UTC | |
by borisz (Canon) on Jan 05, 2005 at 22:40 UTC | |
|
Re: finding the path of the script running as Win service
by Joost (Canon) on Jan 05, 2005 at 22:22 UTC | |
by punkish (Priest) on Jan 05, 2005 at 22:44 UTC | |
by jdalbec (Deacon) on Jan 06, 2005 at 02:08 UTC |