Is there a way to pass command line arguments to a service invoked by mono-service? All of the command line arguments seem to be absorbed by mono-service instead of passed to the service.
-
are you using an Assembly with a Main method? [You should already be able to 'catch' the command line arguments from there](https://github.com/sehe/mono/commit/64ecfe59e7cffb1bbef54be2e9fc32bdc755fd12#commitcomment-626702), but see [my post](http://stackoverflow.com/questions/7636395/passing-command-line-arguments-to-mono-service/7636498#7636498) for a possible patch if it really wasn't by design. – sehe Oct 03 '11 at 15:07
1 Answers
Update: as per my patch that went in end 2011 you can now use the intended interface of
mono-service
.
The idiomatic way to do things would be to use an app.config file to contain Configuration Sections (in XML).
Update
That seems odd. The assebmblyArgs
[sic] are being passed as part of the activationAttributes
to AppDomain.CreateInstanceAndUnwrap Method (String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[])
, but being ignored in the call to OnStart
.
You could try compiling a modified version of mono-service.exe
using the following source:
* see github gist or commit for review
Compile to mono-service.exe
with -r:System.ServiceProcess.dll -r:Mono.Posix.dll -unsafe
OLDER STUFF:
Update 1 Strike that. Judging from the code you should just be able to pass options trailing the assembly name.
This implies that the following should do what you expect:
mono-service -l:/root/service-lock MyService.exe /Param1 /Param2 bla.txt

- 374,641
- 47
- 450
- 633
-
I don't think they're passed to `OnStart`, but rather into `Main`. Let me test and I'll let you know. – David Pfeffer Oct 03 '11 at 15:36
-
1@DavidPfeffer: FYI the patch has been applied to [Mono github](https://github.com/mono/mono/commit/1bedeb9b324f20c6b91276b4f49e2407c9eba194) today by Miguel himself :) This means that you can expect things to work better with params passed to `mono-service` in the future – sehe Oct 22 '11 at 19:37
-
Although it does not seem to be documented anywhere, you can meanwhile use `mono-service service.exe /arg1 /arg2`, with `{"/arg1", "/arg2"}` being passed to `string[] args` of `OnStart`. – christianliebel Jan 26 '16 at 15:05
-
@chliebel yeah. That would make sense because my patch has been applied over 4 years ago now :) That's exactlt the point of the patch – sehe Jan 26 '16 at 15:12
-
@sehe Good work! Would you mind updating your answer accordingly? Since it’s possible to specify args now… :) – christianliebel Jan 26 '16 at 15:34