Facing error when python exe service is started after nssm

对着背影说爱祢 提交于 2021-02-11 15:07:57

问题


I have a situation where i have to run a python.exe as a service in NSSM. To test, I have created .exe file which has only import pandas as pd in it. I created the service in NSSM successfully. But when I start the service I get error windows could not start the service on local computer the service did not return an error.

What else can I do to tackle this problem?

Trust me I have tried all solutions in stack overflow.

  1. I closed cmd when starting service.
  2. Gave all control to network service


回答1:


  1. Install Python in Program Files or another public folder if not already.

  2. If your service are running as the NETWORK SERVICE run CMD with psexec as the NETWORK SERVICE:

     psexec -i -u "nt authority\network service" cmd.exe
    
  3. Install pandas with this cmd.

  4. In cmd check if you can run python and import pandas.

  5. Since services can't have windows you need to somehow check result of your program. For example redirect exception to a file:

     try:
         import pandas
         # do something
     except Exception as e:
         with open(r'c:/service_output.txt', 'wt+') as fd:
             fd.write(repr(e))
    


来源:https://stackoverflow.com/questions/65020274/facing-error-when-python-exe-service-is-started-after-nssm

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