Merge pull request #963 from kebby/master
[mono.git] / mcs / class / System / System.Diagnostics / Process.cs
index 63a045fd6284626669b30c9abb38ee12ed4c334e..af427037b285cfc9ae8e1b4e7aa7183d1fddc04b 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;
                }
@@ -1514,8 +1514,8 @@ namespace System.Diagnostics {
                [ComVisibleAttribute(false)] 
                public void CancelErrorRead ()
                {
-                       if (process_handle == IntPtr.Zero || output_stream == null || StartInfo.RedirectStandardOutput == false)
-                               throw new InvalidOperationException ("Standard output has not been redirected or process has not been started.");
+                       if (process_handle == IntPtr.Zero || error_stream == null || StartInfo.RedirectStandardError == false)
+                               throw new InvalidOperationException ("Standard error has not been redirected or process has not been started.");
 
                        if ((async_mode & AsyncModes.SyncOutput) != 0)
                                throw new InvalidOperationException ("OutputStream is not enabled for asynchronous read operations.");