【发布时间】:2021-03-24 16:28:09
【问题描述】:
我用 python 创建了一个 Windows 服务。当我以调试模式运行它时它运行良好,但是当我启动服务时它不起作用。这是我的脚本示例:
def run(param):
subprocess.Popen(["C:\\SER\\txt_write.pyw",param], shell=True)
#txt_write is a simple script: put the parameter into b.txt
def add_param():
x="123456"
run(x)
class PythonCornerExample(SMWinservice):
_svc_name_ = "name"
_svc_display_name_ = "name disp"
_svc_description_ = "desc"
def start(self):
self.isrunning = True
def stop(self):
self.isrunning = False
def main(self):
i=0
while self.isrunning:
add_param()
f= open("C:\\SER\\a.txt","a+")
f.write("xyz")
f.close()
time.sleep(25)
if __name__ == '__main__':
PythonCornerExample.parse_command_line()
因此,当我在调试模式下运行此脚本时,它会将“xyz”文本放入 a.txt,并调用另一个 Python 脚本,将参数 (123456) 放入 b.txt。这就是我希望它的工作方式。
我的问题是,作为 Windows 服务安装 a.txt 可以工作,但 b.txt 不能。
我的脚本有什么问题?为什么在debug模式下可以,为什么在Services模式下会出错?
【问题讨论】:
标签: python windows service windows-services