我在python中有简单的Windows服务,我需要运行一些外部应用程序。我尝试使用os.system
和subprocess.call
,但它在窗口服务中不起作用。
我的简单服务:
class AppServerSvc(win32serviceutil.ServiceFramework):
_svc_name_ = "MyService1"
_svc_display_name_ = "Test Service1"
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.hWaitStop)
def SvcDoRun(self):
########## That is my trial #################
os.system("C:\\Windows\\System32\\notepad.exe")
#############################################
rc = None
while rc != win32event.WAIT_OBJECT_0:
rc = win32event.WaitForSingleObject(self.hWaitStop, 3000)
if __name__ == '__main__':
win32serviceutil.HandleCommandLine(AppServerSvc)