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

I have recently asked a few questions re converting a perl program to an exe, and then, that exe to a Win32 service (see Perl script to EXE to Windows Service.

With the help of various wise monks, I have been able to solve most of my problems. I am now stuck with one bit that is posing to be particularly vexing --

In order to provide user-control, my program uses an external config file that is read in during the Win32 service startup loop. So, a user can stop the service, change config params, and restart the service. It works.

But, here is the problem -- the config file itself has to be specified in the program with its path hardcoded. As I understand, the Win32 service control manager (SCM) doesn't understand relative paths as the service runs as a local system account. So, before I can convert my perl script to an exe via pp, the script has to have the config file long path encoded in it. Of course, when I transfer the exe to another computer, the path may not be the same as mine (for example, my computer, doesn't have a C: drive -- for some reason, it is now E: drive). So, I have a bit of code like so

BEGIN { open(STDERR, ">>E:/foo/bar.err") or die "invisible error"; warn "$0 started ".localtime().$/; } .. # and then, further down .. Config::Simple->import_from('E:/foo/foo.conf', \%c);
It is these hardcoded instances of pathnames that I want to avoid. Or, at least make them configurable on the target machine. In other words, I want to above paths to be malleable when I convert foo.pl -> foo.exe.
BEGIN { open(STDERR, ">>$path/bar.err") or die "invisible error"; warn "$0 started ".localtime().$/; } .. # and then, further down .. Config::Simple->import_from('$path/foo.conf', \%c);
Then I want to copy foo.exe and foo.conf to the target user under, say, P:\programs\foo\ (or some arbitrary directory), and change $path to P:/programs/foo/ within foo.exe before converting foo.exe -> Win32 service.

How to do that?

Replies are listed 'Best First'.
Re: how to make pp-created exe read external config values
by yacoubean (Scribe) on Jan 04, 2005 at 23:34 UTC
    I haven't followed all of your travails up to this post, but you may want to try the Windows environment variables. In Windows 2000, if you right click 'My Computer' and do Properties, click Advanced, then Environment Variables, you can set the base working path for your script as a system variable (or a user variable, whatever you deem appropriate). This node seems to have a good discussion of using Windows environment variables. Of course, it seems like it would be easier to me if you put the base bath in a Perl variable, but its up to you. :)

    My home on the web: http://www.techfeed.net/

      but you may want to try the Windows environment variables

      I guess my question, in short, is -- how do I feed in some variable to an already packaged .EXE before I convert it into a service? So, it is kinda like an installation issue -- I want to be able to intelligently "install" my .EXE on the target computer, give it the correct path name, and then make it into a service. From then on, it will happily read the external config file and work well.

      The node you mentioned above seems to be a discussion of CGI environment variables.

Re: how to make pp-created exe read external config values
by holli (Abbot) on Jan 04, 2005 at 23:51 UTC
    PerlSvc::exe()
      PerlSvc::exe()

      I can't figure out for the life of me how this is supposed to help me in what I need.

        That is a function that returns the pah to the .exe file.