Console application does not correctly parse arguments with spaces

I created a .NET console application that receives some command line arguments.

When I pass args with spaces, I use quotation marks to cover these arguments so that they are not split by cmd:

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

If I run the application on Windows XP, it works fine: it receives 3 arguments:

  • argument1
  • argument 2
  • third argument

However, if I run it on Windows Server 2008, it seems to ignore quotation marks: it receives 6 arguments:

  • argument1
  • "argument
  • 2 "
  • "button
  • third
  • argument "

Any ideas why?

NOTE. I printed arguments only when Main starts execution with this code:

Console.WriteLine("Command line arguments:");
foreach (string arg in args)
{
    Console.WriteLine("# " + arg);
}
+3
source share
2

, , , ".

, , .

, " .".

+7

, .

C:\MyAppDir > MyApp1\ " 2 \" \ " \"

0

All Articles