Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Console app not parsing correctly args with white spaces

I've created a .NET console application that gets some command line arguments.

When I pass args with white spaces, I use quotes to embrace these arguments so that they are not splitted by cmd:

C:\MyAppDir> MyApp argument1 "argument 2" "the third argument"

If I execute the app in Windows XP it works fine: it gets 3 arguments:

  • argument1
  • argument 2
  • the third argument

However, if i execute it in Windows Server 2008 it seems to ignore quotes: it gets 6 arguments:

  • argument1
  • "argument
  • 2"
  • "the
  • third
  • argument"

Any ideas why?

NOTE: I printed arguments just when Main starts execution using this code:

Console.WriteLine("Command line arguments:");
foreach (string arg in args)
{
    Console.WriteLine("# " + arg);
}
like image 926
German Latorre Avatar asked May 11 '12 09:05

German Latorre


2 Answers

Make sure the character you are typing is indeed the double quote ".

Maybe it's a character that looks like it.

I know my Greek language settings produce a " but it's not read that way.

like image 107
ericosg Avatar answered Oct 12 '22 10:10

ericosg


Please Try it.

C:\MyAppDir> MyApp argument1 \"argument 2\" \"the third argument\"

like image 24
Shiraj Momin Avatar answered Oct 12 '22 12:10

Shiraj Momin