[Mono-bugs] [Bug 59576][Maj] New - Incorrect command line parameters passed by System.Diagnostics.Process

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Thu, 3 Jun 2004 16:28:33 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by dol@2a.pl.

http://bugzilla.ximian.com/show_bug.cgi?id=59576

--- shadow/59576	2004-06-03 16:28:33.000000000 -0400
+++ shadow/59576.tmp.15831	2004-06-03 16:28:33.000000000 -0400
@@ -0,0 +1,110 @@
+Bug#: 59576
+Product: Mono: Runtime
+Version: unspecified
+OS: 
+OS Details: Windows XP SP1
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Major
+Component: misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: dol@2a.pl               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Incorrect command line parameters passed by System.Diagnostics.Process
+
+Description of Problem:
+
+On Win32 command line parameters to processes created via
+System.Diagnostics.Process are passed incorrectly to the new process. This
+problem is connected with an idiosyncrasy of the Win32 CreateProcess call.
+
+
+Steps to reproduce the problem:
+
+1. Create test1.cs file with the following contents:
+
+---- test1.cs
+using System.Diagnostics;
+
+class test1
+{
+  public static void Main()
+  {
+    Process p = new Process();
+
+    p.StartInfo.UseShellExecute = false;
+    p.StartInfo.FileName = "notepad.exe";
+    p.StartInfo.Arguments = "test1.cs";
+
+    p.Start();
+
+  }
+}
+---- test1.cs end
+
+2. Compile test1.cs to test1.exe.
+
+3. Start test1.exe in directory containing test1.cs file.
+
+
+Actual Results:
+
+Notepad is started as expected, but test1.cs file is not loaded.
+
+
+Expected Results:
+
+Notepad should start and test1.cs should be loaded into it.
+
+
+How often does this happen? 
+
+Always.
+
+
+Additional Information:
+
+As I have mentioned at the beginning of the report, CreateProcess call in
+Win32 has one 'feature' that is poorly documented and frequently confuses
+programmers. Its second parameter 'lpCommandLine' should contain full path
+of the started EXE file (ARGV[0]), followed by actual command line
+parameters (ARGV[1],...).
+
+In the above example .NET runtime sets command line to:
+
+"notepad.exe" test1.cs
+
+
+Mono sets this to:
+
+test1.cs
+
+
+It seems to me that the problem is in CreateProcess call in
+mono/mono/metadata/process.c file in
+ves_icall_System_Diagnostics_Process_Start_internal function.
+
+In line 866 (in version 1.24 of the file):
+
+ret=CreateProcess (shell_path, mono_string_chars (cmd), NULL, NULL, TRUE,
+CREATE_UNICODE_ENVIRONMENT, env_vars, dir, &startinfo, &procinfo);
+
+second parameter - currently 'mono_string_chars (cmd)' should be a
+concatenation (using C# syntax): "\"" + shell_path + "\" " + cmd.
+
+It seems that putting EXE name in quotes does not cause problems and it is
+necessary for sure, when full path name contains spaces (otherwise
+parameter parsing code in various C libs can get confused).
+
+I cannot provide you with a patch because I do not have a full compilation
+environment to verify it. Sorry.
+
+I can only suggest downloading Process Explorer utility from:
+http://www.sysinternals.com/ntw2k/freeware/procexp.shtml
+
+With this utility, one can easily see various details about running
+processes, including command line parameters.