protected virtual void PrepareStart(ProcessArgs arguments, bool silent) { _exitedEventPublished = false; StandardOutputArray.Clear(); _standardOutput = null; ErrorOutputArray.Clear(); _errorOutput = null; _batchModeOutput = null; _batchOutputString = null; Killed = false; ExitCode = 0; _startInfo = new ProcessStartInfo { FileName = ExecutablePath, UseShellExecute = false }; if (arguments != null) { _startInfo.Arguments = arguments.ToCliArgs(); } if (!string.IsNullOrEmpty(WorkingDirectory)) { _startInfo.WorkingDirectory = WorkingDirectory; } if (silent) { _startInfo.WindowStyle = ProcessWindowStyle.Hidden; _startInfo.CreateNoWindow = true; } if (RedirectOutput) { _startInfo.RedirectStandardError = true; _startInfo.RedirectStandardOutput = true; if (RedirectedOutputEncoding != null) { _startInfo.StandardErrorEncoding = RedirectedOutputEncoding; _startInfo.StandardOutputEncoding = RedirectedOutputEncoding; } } _process = new Process { StartInfo = _startInfo }; if (RedirectOutput) { _process.OutputDataReceived += OnProcessOnOutputDataReceived; _process.ErrorDataReceived += OnProcessOnErrorDataReceived; } if (OnProcessExit != null) { _process.EnableRaisingEvents = true; _process.Exited += ProcessOnExited; } }
protected virtual void OnProcessOnOutputDataReceived(object sender, DataReceivedEventArgs args) { if (!string.IsNullOrEmpty(args.Data)) { StandardOutputArray.Add(args.Data); } }