void process_ErrorDataReceived(object sender, DataReceivedEventArgs e) { RoboDataReceivedEventArgs eventArgs = new RoboDataReceivedEventArgs(e.Data ?? string.Empty); lock (LockObject) { if (IntProgress(eventArgs.Data) == null) StandardErrorBuilder.AppendLine(e.Data); } if (OnErrorDataReceived != null) OnErrorDataReceived(sender, eventArgs); }
private bool StartProcess(string args) { ProcessStartInfo ps = new ProcessStartInfo { FileName = CMD, UseShellExecute = false, RedirectStandardError = true, RedirectStandardOutput = true, CreateNoWindow = true, Arguments = args, StandardOutputEncoding = Encoding.GetEncoding(437), StandardErrorEncoding = Encoding.GetEncoding(437), }; try { using (Process p = Process.Start(ps)) { CopyProcess = p; p.OutputDataReceived += process_OutputDataReceived; p.ErrorDataReceived += process_ErrorDataReceived; p.BeginOutputReadLine(); p.BeginErrorReadLine(); p.WaitForExit(); CopyProcess = null; return !IsKilled && (p.ExitCode >= 0 || p.ExitCode <= 2); } } catch (Exception ex) { lock (LockObject) { StandardErrorBuilder.Append(ex.Message); } RoboDataReceivedEventArgs eventArgs = new RoboDataReceivedEventArgs(ex.Message); OnErrorDataReceived(this, eventArgs); return false; } }