0
不行,我有一個Python程序,該程序將調用一個cmd(showTxt.exe)做一些事情,環境路徑窗口服務
當我運行這個Python程序in console
,它工作正常(的showTxt。 exe文件)。
p = Tarser(self.conf_parser)
p.parse()
但是當我運行該程序作爲windows service
,該showTxt.exe似乎不起作用。
我已經將showTxt.exe的目錄路徑保存到environment path
。
我檢查Event Logs
,沒有錯誤或警告
,改變showTxt.exe的安全設置不起作用。
class MyService(win32serviceutil.ServiceFramework):
"""Windows Service."""
os.chdir(os.path.dirname(__file__))
ini = "tarser_service.ini"
conf_parser = ConfigParser.SafeConfigParser()
conf_parser.read(ini)
_svc_name_, _svc_display_name_, _svc_description_ = get_win_service(conf_parser)
def __init__(self, args):
if os.path.dirname(__file__):
os.chdir(os.path.dirname(__file__))
win32serviceutil.ServiceFramework.__init__(self, args)
# create an event that SvcDoRun can wait on and SvcStop can set.
self.stop_event = win32event.CreateEvent(None, 0, 0, None)
def SvcDoRun(self):
self.Run()
win32event.WaitForSingleObject(self.stop_event, win32event.INFINITE)
def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.stop_event)
LoggerInstance.log("Tarser service is stopped")
self.ReportServiceStatus(win32service.SERVICE_STOPPED)
sys.exit()
def Run(self):
LoggerInstance.log("Tarser service is running, configuration: %s" %(self.ini,))
if ((not self.conf_parser.has_section('Tsc')) or
(not self.conf_parser.has_option('Tsc', 'check_interval')) or
(not self.conf_parser.has_option('Tsc', 'running_time'))):
LoggerInstance.log('Tarser service: no Tsc service parameters')
self.SvcStop()
# set configuration parameters from ini configuration
self.check_interval = self.conf_parser.getint('Tsc', 'check_interval')
running_time = self.conf_parser.get('Tsc', 'running_time')
TscCheck_time = time.strptime(running_time, "%H %M")
while 1:
curr_time = time.gmtime()
if curr_time.tm_hour == TscCheck_time.tm_hour and curr_time.tm_min == TscCheck_time.tm_min:
p = Tarser(self.conf_parser)
p.parse()
#LoggerInstance.log("Tarser service: sleep %d seconds" %self.check_interval)
time.sleep(self.check_interval)