我想通过python提示Windows服务中的shell。以下是我的代码。它运行购买提示正在运行背景而不是显示。非常感谢你!
import win32service
import win32serviceutil
import win32event
import requests
import sys
import subprocess
import os
class PySvc(win32serviceutil.ServiceFramework):
_svc_name_ = "ServicePython" # NET START/STOP the service by the following name
_svc_display_name_ = "ServicePython Service" # name in the Service Control Manager (SCM)
_svc_description_ = "This service writes stuff to a file" # description in the SCM
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self,args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
def SvcDoRun(self):
import servicemanager
self.start()
win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE)
def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) #tell the SCM
win32event.SetEvent(self.hWaitStop) # fire the stop event
self.stop()
def start():
pass
def stop():
pass
class MyService(PySvc):
def start(self):
os.system("start cmd.exe /k \"cd /d C:\\ & dir\"") ####this does not show, runs at background only
if __name__ == '__main__':
sys.argv.append("start")
win32serviceutil.HandleCommandLine(MyService)