[Mono-list] Command line parameters with spaces

Michael Hutchinson m.j.hutchinson at gmail.com
Thu Jan 20 16:51:13 EST 2011


On Thu, Jan 20, 2011 at 3:42 PM, karolo84 <karolo84 at binkmail.com> wrote:
> But I have not yet successfully got that running under Linux + Mono. In fact
> I haven't even successfully submitted a simple space containing string to
> that app...
>
> I tried thing like
>
> mono app.exe "a b"
> mono app.exe "a\ b"
> mono app.exe 'a b'
> -> all received as two strings: a and b
>
> mono app.exe ´a b´
> -> UTF-8 encoding error
>
> mono app.exe `a b`
> -> tries to execute a
>
> What can I do to pass a SQL query as a command line argument to my program?
> Searching the forum and with google pointed to Mono.Options but that is the
> developer side of the problem, not the app users side... Reflector says the
> app just uses plain old args[] to determine the number of parameters...

The argument handling is a function of your shell, not Mono. Using
bash on a Mac works fine - quoted args with spaces gets passed as
single strings. Are you using some strange shell?

//test.cs
class Test {
        static void Main (string[] args) {
                foreach (string arg in args)
                        System.Console.WriteLine (arg);
        }
}

$ gmcs test.cs
$ mono test.exe
$ mono test.exe "foo bar" baz
foo bar
baz


-- 
Michael Hutchinson
http://mjhutchinson.com


More information about the Mono-list mailing list