Пример #1
0
 private static void ErrorHandler(object sendingProcess,
                                  DataReceivedEventArgs outLine)
 {
     // Collect the sort command output.
     if (!string.IsNullOrEmpty(outLine.Data))
     {
         if (outLine.Data.StartsWith("INFO"))
         {
             status.SendInfoMessage(outLine.Data);
         }
         else
         {
             status.SendErrorMessage(outLine.Data);
         }
     }
 }
Пример #2
0
        public int RunProcess(PipelineStatus status)
        {
            try
            {
                process.Start();

                // do not wait for the child process to exit before
                // reading to the end of its redirected stream.
                // process.WaitForExit();

                // read the output stream first and then wait.
                //output = process.StandardOutput.ReadToEnd();
                //Debug.Log(output);
                process.BeginOutputReadLine();
                process.BeginErrorReadLine();
                process.WaitForExit();
                exitCode = process.ExitCode;
            }
            catch (ThreadAbortException e)
            {
                process.Kill();
                status.SendMessage("Process exited by user");
            }
            catch (System.Exception e)
            {
                status.SendErrorMessage("Run error" + e.ToString()); // or throw new Exception
                exitCode = process.ExitCode;
            }
            finally
            {
                status.SendMessage("Process finished with exit code " + exitCode);
                process.Dispose();
                hasFinished = true;
                process     = null;
            }
            return(exitCode);
        }