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?


In reply to how to make pp-created exe read external config values by punkish

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.