Merge pull request #898 from UCIS/patch-3
[mono.git] / mcs / class / System / System.Diagnostics / Process.cs
index 63a045fd6284626669b30c9abb38ee12ed4c334e..7a63ce0377c62529dbf33b5f8c9718d401f74ff9 100644 (file)
@@ -918,7 +918,7 @@ namespace System.Diagnostics {
                                                                  IntPtr stderr,
                                                                  ref ProcInfo proc_info);
 
-               private static bool Start_shell (ProcessStartInfo startInfo)
+               private static bool Start_shell (ProcessStartInfo startInfo, Process process)
                {
                        ProcInfo proc_info=new ProcInfo();
                        bool ret;
@@ -945,6 +945,9 @@ namespace System.Diagnostics {
                                throw new Win32Exception (-proc_info.pid);
                        }
 
+                       process.process_handle = proc_info.process_handle;
+                       process.pid = proc_info.pid;
+                       process.StartExitCallbackIfNeeded ();
                        return(ret);
                }
 
@@ -1156,7 +1159,7 @@ namespace System.Diagnostics {
                        if (startInfo.UseShellExecute) {
                                if (!String.IsNullOrEmpty (startInfo.UserName))
                                        throw new InvalidOperationException ("UserShellExecute must be false if an explicit UserName is specified when starting a process");
-                               return (Start_shell (startInfo));
+                               return (Start_shell (startInfo, process));
                        } else {
                                return (Start_noshell (startInfo, process));
                        }
@@ -1176,12 +1179,9 @@ namespace System.Diagnostics {
                        if (startInfo == null)
                                throw new ArgumentNullException ("startInfo");
 
-                       Process process = null;
-                       if (!startInfo.UseShellExecute) {
-                               process = new Process();
-                               process.StartInfo = startInfo;
-                       }
-                       if (Start_common(startInfo, process))
+                       Process process = new Process();
+                       process.StartInfo = startInfo;
+                       if (Start_common(startInfo, process) && process.process_handle != IntPtr.Zero)
                                return process;
                        return null;
                }