Creating a Python script that runs as a Windows service using sc.exe

为君一笑 提交于 2020-01-03 21:47:28

问题


I would like to create a Windows Service using a batch script for a Python script that I have written. I decided to do some experimenting with sc. Here is the line that I used:

sc create RoundTripService binPath="C:\Python27\python.exe C:\script.py" type=own error=ignore start=auto

Unfortunately, when I do so, the console is giving me a printout of the Description/Usage/Options, etc. of sc instead.


回答1:


SC is overly strict about spaces in its command line and you are receiving the error because you have no space after the "binPath=" and "type=" components. Run

SC CREATE /?

at a DOS prompt to see how your command line should be constructed.

But even if you get SC to install python, you will run into the dreaded "Error 1053" when you attempt to start the service! This is because Python.exe is not a true Windows Service executable and can not react to the Windows Service Control Manager's request to start the service. You will need a "service wrapper" (like Microsoft's SRVANY, though it has some shortcomings) to intercept the requests from the Windows Service Control Manager and start your python script.



来源:https://stackoverflow.com/questions/23902828/creating-a-python-script-that-runs-as-a-windows-service-using-sc-exe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!