How to pass my own command line args

3,883 views
Skip to first unread message

John Simons

unread,
May 21, 2011, 9:01:17 PM5/21/11
to topshelf...@googlegroups.com
What is the recommended way to pass my own command line args?
How do I retrieve them?
I want to pass -port:8080

Cheers, John

Dru Sellers

unread,
May 23, 2011, 7:52:03 PM5/23/11
to topshelf...@googlegroups.com
i am not sure if we have an exact way to do that yet, but until someone corrects me, or I put 2 and 2 together, you can use the Environment.CommandLine

-d

John Simons

unread,
May 23, 2011, 11:55:25 PM5/23/11
to topshelf...@googlegroups.com
Hi Dru,

I've looked at the source code, and I couldn't figure it out :(
But from what I saw, the current API has the concept of Option and Builder, I guess it would be really nice to extend the API to support being able to pass extra command line args and expose them to the user service.
Not sure how would this work with shelves!

For now I'm using App.config.

Cheers
John


From: Dru Sellers <d...@drusellers.com>
To: topshelf...@googlegroups.com
Sent: Tuesday, 24 May 2011 9:52 AM
Subject: Re: [topshelf-discuss] How to pass my own command line args

Travis Smith

unread,
May 24, 2011, 8:09:56 AM5/24/11
to topshelf...@googlegroups.com
You can always access the command line with Environment.CommandLine.
Topshelf doesn't currently support passing the command line along to
services. App.config setting would be the preferred method to handle
this in both normal and bottle based service hosting.

-Travis

On Mon, May 23, 2011 at 11:55 PM, John Simons

Dru Sellers

unread,
May 24, 2011, 8:24:13 AM5/24/11
to topshelf...@googlegroups.com
@chris, with the new builder stuff, would this be easier to do now?
@john: how are you want to receive the command line? do you want all of it? or just the non-TS bits?

-d

Chris Patterson

unread,
May 24, 2011, 10:14:16 AM5/24/11
to topshelf...@googlegroups.com
In theory, we could take any unmatched command-line arguments and pass them to the service, but then we would have to know that we need to pass these to the service when it actually runs as a service.

As Travis said, using the App.config would likely be a better win here, since configuring the command line as a service (set via the ImagePath in the registry) could lead to some confusion, etc.

John Simons

unread,
May 25, 2011, 7:40:13 AM5/25/11
to topshelf...@googlegroups.com
I would like to get all non TS args, maybe exposed via the api as a Dictionary.

John

Sent: Tuesday, 24 May 2011 10:24 PM

Dru Sellers

unread,
May 25, 2011, 9:34:08 AM5/25/11
to topshelf...@googlegroups.com
Hmmm, ok.
Have to ponder on that one a bit.
Thanks john!
-d

Matt Howells

unread,
May 12, 2015, 11:07:16 AM5/12/15
to topshelf...@googlegroups.com
It's been four years - what are the results of your pondering? I really need to install the service with some custom command-line arguments.

Chris Patterson

unread,
May 12, 2015, 11:47:11 AM5/12/15
to topshelf...@googlegroups.com
Hmm, let me think... :)


--
You received this message because you are subscribed to the Google Groups "topshelf-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to topshelf-discu...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chris Patterson

unread,
May 12, 2015, 11:59:31 AM5/12/15
to topshelf...@googlegroups.com
I just checked, the extra command line arguments are not preserved during install.

Piers Williams

unread,
Jun 22, 2015, 2:34:54 AM6/22/15
to topshelf...@googlegroups.com
So I'd just like to put my hand up and say how useful this would be. The use case I'm targeting here is that I install multiple instances of a service, which (of course) share an app.config, so I want to configure some aspects of them independently. At present I'm ending up doing this via the service Instance Name (and then selectively reading different sets of settings from the shared app.config), but this seems really hacky, not to mention that it takes a strong dependency on TopShelf never changing that -instance argument. 

A simple mechanism to declare cmd args that would be passed all the way to the service would be really helpful, or just a simple mechanism to extend whatever image path / args get put into the registry during service installation.

Travis Smith

unread,
Jun 22, 2015, 7:38:24 AM6/22/15
to topshelf...@googlegroups.com
At this point, I don't expect I'll fix this nor do I believe Chris has plans to do so. I believe the behaviour will be confusing and non-intuitive -- there is no visibility into what's been injected in the ImagePath. I believe you will be better served by configuration management in other, more explicit, ways. 

Yes, this is a feature people would find useful. But I expect it will cause us more support issues than people it will make happy. Right now, I believe we're better served by failing to support custom command line arguments. If someone comes up with an implementation or idea that resolves my concerns, then I'm happy to reconsider. 
--
-Travis

Victor Feinman

unread,
Sep 30, 2015, 8:15:54 AM9/30/15
to topshelf-discuss
Travis,
 
Might I ask why TopShelf supports custom command line arguments at all, if you don't plan on implementing them all the way to the service? For most of us (I would think), the end goal with TopShelf is installing a service, why tease us with handling command line arguments when running the console app, but drop them at the service?
 
-Victor

Travis Smith

unread,
Sep 30, 2015, 8:41:31 AM9/30/15
to topshelf-discuss
Sure, you are welcomed to asked Victor. 

Though I'm missing a brilliant answer here. I think the real answer is that it's easy, and it supports enough people's use cases that it just happened. And by easy, I mean, "Hey, use this API that we already use" easy. So zero effort other than a bit of documentation. 


IanYates

unread,
Mar 16, 2016, 10:32:22 PM3/16/16
to topshelf-discuss
FYI: I found this GitHub repo which seems to wrap it up pretty well. https://github.com/r1pper/Topshelf.StartParameters
Reply all
Reply to author
Forward
0 new messages