private void CaptureOutput() { try { if (OutputStreamChanged != null) { char[] buffer = new char [1024]; int nr; while ((nr = StandardOutput.Read(buffer, 0, buffer.Length)) > 0) { if (OutputStreamChanged != null) { OutputStreamChanged(this, new string (buffer, 0, nr)); } } } } catch (ThreadAbortException) { // There is no need to keep propagating the abort exception Thread.ResetAbort(); } finally { // WORKAROUND for "Bug 410743 - wapi leak in System.Diagnostic.Process" // Process leaks when an exit event is registered WaitHandle.WaitAll(new WaitHandle[] { endEventErr }); OnExited(this, EventArgs.Empty); //call this AFTER the exit event, or the ProcessWrapper may get disposed and abort this thread if (endEventOut != null) { endEventOut.Set(); } } }
private void CaptureOutput() { try { if (OutputStreamChanged != null) { char[] buffer = new char [1024]; int nr; while ((nr = StandardOutput.Read(buffer, 0, buffer.Length)) > 0) { if (OutputStreamChanged != null) { OutputStreamChanged(this, new string (buffer, 0, nr)); } } } } catch (ThreadAbortException) { // There is no need to keep propagating the abort exception Thread.ResetAbort(); } finally { // WORKAROUND for "Bug 410743 - wapi leak in System.Diagnostic.Process" // Process leaks when an exit event is registered if (endEventErr != null) { endEventErr.WaitOne(); } try { if (HasExited) { operation.ExitCode = ExitCode; } } catch { // Ignore } try { OnExited(this, EventArgs.Empty); } catch { // Ignore } lock (lockObj) { //call this AFTER the exit event, or the ProcessWrapper may get disposed and abort this thread if (endEventOut != null) { endEventOut.Set(); } } taskCompletionSource.SetResult(operation.ExitCode); } }
public string CaptureOutputUntilTheNextCommandRequest() { var playerOutput = ""; var nextChar = (char)StandardOutput.Read(); while (nextChar != '>' && nextChar != 0xffff) { playerOutput += $"{nextChar}"; nextChar = (char)StandardOutput.Read(); } playerOutput += $"{nextChar}"; return(playerOutput); }
public IEnumerable <string> GetOutput() { int stdOutIndex = 0; int stdErrorIndex = 0; int BUF_SIZE = 4096; string output = ""; while (!HasExited) { char[] buf = new char[BUF_SIZE]; if (StandardOutput.Peek() > -1) { stdOutIndex += StandardOutput.Read(buf, stdOutIndex, BUF_SIZE); output = (new string(buf)).Trim(); } else if (StandardError.Peek() > -1) { stdErrorIndex += StandardError.Read(buf, stdErrorIndex, BUF_SIZE); output = (new string(buf)).Trim(); } else { output = ""; } if (!string.IsNullOrEmpty(output)) { yield return(output); } } output = (StandardOutput.ReadToEnd().Trim() + "\r\n" + StandardError.ReadToEnd().Trim()).Trim(); //Console.WriteLine($"Final output: {output}"); if (!string.IsNullOrEmpty(output)) { yield return(output); } }