I have an issue that\'s nearly identical to the one outlined here (Console app not parsing correctly args with white spaces) but that answer has no bearing on my situation.
Try this, Join the args into a string again, then Split that string on the double quote character.
string parms = String.Join(" ", args);
string[] arguments = parms.Split('\"');
...
BTW: This is a work around for the problem John Koerner has explained.
It is caused by the \"
at the end of your first argument.
If you remove the trailing slash or add an extra slash before the quote then you will get two arguments. The quote is being escaped and is considered part of the first argument until it hits the next quote 2 characters later. After that you are no longer inside of a quote and thus each space results in another argument added to the args
array.
This is caused by the fact that .Net uses CommandLineToArgvW
to process command line arguments and the rules it uses to handle escaping of characters.
Jon Galloway has a writeup on this
To quote:
CommandLineToArgvW has a special interpretation of backslash characters when they are followed by a quotation mark character ("), as follows:
- 2n backslashes followed by a quotation mark produce n backslashes followed by a quotation mark.
- (2n) + 1 backslashes followed by a quotation mark again produce n backslashes followed by a quotation mark.
- n backslashes not followed by a quotation mark simply produce n backslashes.
It is because youre slash here Working\"
, when you add another slash it works correctly I believe
so make It <snip>...Working\\"
edit: I just tested it myself, with a double \\
you get 3 items :)
Also see http://blogs.msdn.com/b/twistylittlepassagesallalike/archive/2011/04/23/everyone-quotes-arguments-the-wrong-way.aspx