Python 服务自定义命令参数
我目前正在开发一个 python 程序,它使用 win32service 和 win32serviceutil 作为 Windows 服务运行。该服务按预期运行,甚至在使用 py2exe 之后,一切都很好(该服务监视目标文件夹并自动 FTP 新创建的文件到指定的 FTP 位置)。不过,我想添加一些命令行参数(除了安装、删除、启动、停止等之外)来指定本地和 FTP 目录。关于此的唯一文档是我在以下位置找到的: http://www.py2exe.org/old/
"或者,您可以指定 'cmdline- py2exe 的“style”属性,有效值为“py2exe”(默认值)、“pywin32”或“custom”,指定 py2exe 始终支持的传统命令行。 pywin32 支持的参数(即,从 .py 文件运行服务时支持的参数相同。)“自定义”意味着您的模块应提供一个“HandleCommandLine”函数,负责所有命令行处理。
任何有助于指明正确方向的帮助将不胜感激。为了清楚起见,如果需要任何代码,请告诉我。
谢谢,扎克
I am currently working on a python program which runs as a windows service using win32service and win32serviceutil. The service runs as it should and even after using py2exe, everything is fine (the service monitors target folder(s) and autmotically FTP's newly created files to specified FTP location). I would like, however, to add some command line arguments (in addition to install, remove, start, stop, etc...) for specifying the local and FTP directories. The only documentation on this is what I found at:
http://www.py2exe.org/old/
"Optionally, you can specify a 'cmdline-style' attribute to py2exe, with valid values being 'py2exe' (the default), 'pywin32' or 'custom'. 'py2exe' specifies the traditional command-line always supported by py2exe. 'pywin32' supports the exact same command-line arguments as pywin32 supports (ie, the same arguments supported when running the service from the .py file.) 'custom' means that your module is expected to provide a 'HandleCommandLine' function which is responsible for all command-line handling."
Any help would be appreciated in getting pointed in the right direction. Please let me know if any code is needed for clarity.
Thanks, Zach
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里是一个不错的如何使用自定义
HandleCommandLine
类方法创建服务的示例 - 它是 Pyro 的一部分,但不依赖于 Pyro,而是一个实用程序“抽象基类”,您可以对其进行子类化并让服务运行只需在子类中设置一些内容即可轻松完成。对于您的特定需求,您可以使用它作为模板进行复制和编辑以获得您想要的命令行处理!here is a nice example of how to make a service with a custom
HandleCommandLine
classmethod -- it's part of pyro but has no dependencies on pyro, rather it's a utility "abstract base class" that you can subclass and get a service going with minimum fuss by just setting a few things in your subclass. For your specific needs, you can use it as a template to copy and edit to get the command line handling that you want!