protected virtual void InitializeEvents() { _process.OutputDataReceived += (sender, args) => { if (args.Data != null) { OnOutputDataReceived?.Invoke(sender, args.Data); } }; _process.ErrorDataReceived += (sender, args) => { if (args.Data != null) { OnErrorDataReceived?.Invoke(sender, args.Data); } }; _process.Exited += (sender, _) => { if (sender is Process process) { OnExited?.Invoke(sender, process.ExitCode); } else { OnExited?.Invoke(sender, _process.ExitCode); } }; }
public void Start() { var process = new Process(); process.StartInfo.FileName = this.ExecutablePath; process.StartInfo.Arguments = this.CommandLineArguments; process.StartInfo.CreateNoWindow = true; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.EnableRaisingEvents = true; process.OutputDataReceived += (sender, e) => OnOutputDataReceived?.Invoke(e.Data); process.ErrorDataReceived += (sender, e) => OnErrorDataReceived?.Invoke(e.Data); process.Exited += (sender, e) => OnExited?.Invoke(); process.Start(); if (this.Input != null) { process.StandardInput.WriteLine(this.Input); process.StandardInput.Close(); } process.BeginOutputReadLine(); process.BeginErrorReadLine(); }
public virtual async Task SendInput(string input) { try { await _process.StandardInput.WriteAsync(input !); } catch (Exception e) { OnErrorDataReceived?.Invoke(_process, e.ToString()); } }
public virtual void Proc_ErrorDataReceived(object sender, DataReceivedEventArgs e) { OnErrorDataReceived?.Invoke(sender, e); }