[Mono-devel-list] Arguments with spaces when startingexternalprogram through System.Diagnostics.Process

Jonathan Gilbert 2a5gjx302 at sneakemail.com
Thu May 26 18:56:17 EDT 2005

At 06:16 PM 26/05/2005 -0400, Gonzalo wrote:
>On Thu, 2005-05-26 at 17:59 -0400, Jonathan Gilbert wrote:
>> At 05:53 PM 26/05/2005 -0400, Gonzalo wrote:
>> >You just need to use something like "'argument with spaces'" (note the
>> >single quotes around the argument).
>> I doubt single quotes will work across platforms, though. It would be much
>> better form to use double-quotes, which will be recognized on Windows and
>> presumably other .NET runtimes as well.
>I doubt that people that doubt without testing are right. In fact, this
>time I'm sure they are not right ;-).

You may have tried it yourself with mono on Windows, but I myself tried it
with Microsoft's implementation on Windows. Here is my test:

==========8<===== caller.cs =====8<==========
using System;
using System.Diagnostics;

class MainClass
  static void Main()
    ProcessStartInfo start_info = new ProcessStartInfo();

    start_info.FileName = "dummy.exe";
    start_info.Arguments = "\"hello world\" 'hello world' `hello world`
hello world";

==========8<===== dummy.cs =====8<==========
using System;

class Dummy
  static void Main(string[] args)
    for (int i=0; i < args.Length; i++)
      Console.WriteLine("  {0}: \"{1}\"", i, args[i]);


csc caller.cs
csc dummy.cs


  0: "hello world"
  1: "'hello"
  2: "world'"
  3: "`hello"
  4: "world`"
  5: "hello"
  6: "world"

As you can see, only the double quotes held up.

Cheers :-)
Jonathan Gilbert

More information about the Mono-devel-list mailing list