【问题标题】:Creating a Python script that runs as a Windows service using sc.exe使用 sc.exe 创建作为 Windows 服务运行的 Python 脚本
【发布时间】:2014-07-17 03:47:11
【问题描述】:

我想使用我编写的 Python 脚本的批处理脚本创建一个 Windows 服务。我决定用 sc 做一些实验。这是我使用的行:

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

不幸的是,当我这样做时,控制台却给了我一份 sc 的描述/使用/选项等的打印输出。

【问题讨论】:

    标签: python windows python-2.7 command-line windows-services


    【解决方案1】:

    SC 对其命令行中的空格过于严格,您收到错误消息是因为“binPath=”和“type=”组件后没有空格。运行

    SC 创建 /?

    在 DOS 提示符下查看应该如何构建命令行。

    但是即使你让SC安装python,当你尝试启动服务时,你也会遇到可怕的“错误1053”!这是因为 Python.exe 不是真正的 Windows 服务可执行文件,无法响应 Windows 服务控制管理器启动服务的请求。您将需要一个“服务包装器”(如 Microsoft's SRVANYthough it has some shortcomings)来拦截来自 Windows 服务控制管理器的请求并启动您的 python 脚本。

    【讨论】:

    • 谢谢!我最终确实发现我错过了 '=' 符号后的空格,但我最终得到了 1053 错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-01
    • 2010-09-07
    • 2016-05-17
    • 2014-12-17
    相关资源
    最近更新 更多