如何使用不是由TopShelf识别命令行参数? [英] How can I use CommandLine Arguments that is not recognized by TopShelf?

查看:1134
本文介绍了如何使用不是由TopShelf识别命令行参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过一些自定义参数的控制台应用程序,当我安装并启动它通过TopShelf Windows服务。

I want to pass some custom arguments to the console app when I install and start it as a Windows Service via TopShelf.

当我使用:

MyService install start /fooBar: Test

控制台应用程序失败:

Console application fails:

[失效]命令行一个未知的命令行选项,发现:   DEFINE:Foobar的=测试

[Failure] Command Line An unknown command-line option was found: DEFINE: fooBar = Test

问:

我怎样才能让我的论点是识别的TopShelf,这样我可以消耗他们的价值观?

How can I make my arguments to be recognizable by TopShelf so that I can consume their values?

推荐答案

根据需要指定在这个模式的命令的文档:

According to the documentation you need to specify the commands in this pattern:

-foobar:Test

您还需要添加在您的服务配置的定义:

You also need to add the definition in your service configuration:

string fooBar = null;

HostFactory.Run(configurator =>
{
    configurator.AddCommandLineDefinition("fooBar", f=> { fooBar = f; });
    configurator.ApplyCommandLine();

    // do something with fooBar

    configurator.Service<ServiceClass>(settings =>
    {
        settings.ConstructUsing(s => GetInstance<ServiceClass>());
        settings.WhenStarted(s => s.Start());
        settings.WhenStopped(s => s.Stop());
    });

    configurator.RunAsLocalService();
    configurator.SetServiceName("ServiceName");
    configurator.SetDisplayName("DisplayName");
    configurator.SetDescription("Description");
    configurator.StartAutomatically();
});

这篇关于如何使用不是由TopShelf识别命令行参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆