可以动态接受控制台命令的Windows服务应用程序

发布于 2024-10-01 05:26:03 字数 601 浏览 0 评论 0原文

我只是想对我正在从事的项目提供一些意见。基本上,我正在创建一个服务,该服务通过命令行监视和处理由配置文件和其他参数指定的目录中的新文件。它还应该通过命令行输出文本,即当用户输入“-help”时,它将显示其用法。目标还在于使用户可以动态更改配置文件,因此服务将不断监视配置文件的更改并进行相应调整。

我看到的挑战是尝试巩固通过命令行输入命令、显示输出的能力,就像它是控制台应用程序一样,并使服务在服务控制管理器中运行时能够处理这些命令。到目前为止,在我的研究中,我偶然发现的解决方案似乎展示了如何创建一个也可以作为控制台应用程序运行的 Windows 服务应用程序,但它要么作为其中之一运行,而不是两者都运行。如有任何建议或意见,我们将不胜感激。

更新:

谢谢大家的建议,我做了一些阅读 在各种 Windows 支持的 IPC 机制上。我将我的选择归结为文件映射、命名管道和 RPC。我现在假设 Windows 服务应用程序和帮助程序控制台应用程序将位于同一台计算机上,并且不需要通过网络进行通信。我将首先查看命名管道。

I just wanted some input on a project that I'm working on. Basically, I'm creating a service that monitors and processes new files in a directory specified by a configuration file and other parameters through the command line. It should also output text via the command line, i.e. when a user types in '-help' it will display it's usage. A goal is to also make it so that the user can change the configuration file on the fly, so the service will constantly monitor the config file for changes and adjust accordingly.

The challenge I'm seeing is trying to consolidate the ability to enter commands through the command line, display output, as if it were a console app, and have the service be able process these commands while it is running in the Service Control Manager. So far in my research, the solutions I've stumbled upon seem to show how to create a Windows Service App that can also run as a console app, but it either operates as one or the other, not both. Any suggestions or input is appreciated.

UPDATE:

Thank you all for your suggestions, I did some reading on various Windows supported IPC mechanisms. I boiled my options down to File Mapping, Named Pipes and RPC. I'm assuming for now that the Windows Service app and Helper Console app will be on the same computer and will not need to communicate over a network. I'll be looking at Named Pipes first.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

叫嚣ゝ 2024-10-08 05:26:03

服务需要提供与其通信的可能性,但这不能直接完成,必须通过某种IPC(进程间通信)来完成,这可以是.net Remoting、WCF、tcp/ip。您必须编写一个帮助程序来解析命令行并使用此 IPC 将命令发送到服务,服务可以在接收到命令后做出适当的操作。

The service needs to offer a possibility to communicate with it, but this can't be done directly, it has to be done by some sort of IPC (inter process communication), this could be .net Remoting, WCF, tcp/ip. You will have to write a helper program that parses the command line and uses this IPC to send the commands to the service, which can act appropiately on receiving it.

逆光下的微笑 2024-10-08 05:26:03

我会编写一个控制台应用程序,将请求发送到服务并显示其响应。如果您想聪明一点,可以将这两个部分包含在同一个可执行文件中。我想不出任何方法可以使服务在作为服务运行时写入和读取控制台。

I would write a console app that sends requests to the service and displays its responses. If you wanted to be clever, you could include both parts in the same executable. I can't think of any way to make the service write to and read from the console while it's running as a service.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文