3

I have a Python application that uses ConfigParser.ConfigParser() to access a configuration file. I have created a windows service of the Python application using py2exe. The problem that I have is that the service can only find the configuration file if I place it in windows/system32 folder. I would like to have the configuration file in the same folder where the service was installed. For example, after using py2exe I have the following folder:

c:/temp/dist/winservice.exe
c:/temp/dist/configfile.cfg

Then I do:

winservice.exe install

But the service does not look for the configfile.cfg in path: c:/temp/dist/ but in path: c:/windows/system32/

Is there any way to change that?

Thanks!

4

1 回答 1

0

您可以使用 Inspect 模块获取创建此代码对象的文件的名称。因此,要获取您将使用的文件的路径:inspect.currentframe().f_code.co_filename

因此,要获取 winservice.exe 所在的目录名称:

dirPath = os.path.dirname(inspect.currentframe().f_code.co_filename)

希望能帮助到你

于 2012-12-10T11:21:48.440 回答