private void OnOutputReceived(object sender, string e) { if (!string.IsNullOrEmpty(e)) { _callback.OnOutputLine(e); } }
internal void Start(string commandText) { _command = _remoteSystem.Shell.ExecuteCommandAsynchronously(commandText, Timeout.Infinite); _command.Finished += (sender, e) => _callback.OnExit(((NonHostedCommand)sender).ExitCode.ToString()); _command.OutputReceived += (sender, e) => _callback.OnOutputLine(e.Output); _command.RedirectErrorOutputToOutput = true; _command.BeginOutputRead(); }
private void OnOutputReceived(object sender, string unorderedText) { // TODO: rajkumar42 The OutputReceived event in liblinux has some issues. If we stick with liblinux, we should fix it: // 1. It kicks off a different thread pool thread every time data is received. As such there is no // way to order the input. // 2. The shell in Linux keeps a queue of input. If a component only obtains the input through the // output received event, then nothing will ever drain the output. // // Suggested fix: Add a ReadLine async method to the shell and remove the output received event // TODO: rajkumar42, this breaks when logging in as root. IEnumerable <string> linesToSend = null; lock (_lock) { string text = _shellStream.ReadToEnd(); if (string.IsNullOrEmpty(text)) { return; } _lineBuffer.ProcessText(text, out linesToSend); } foreach (string line in linesToSend) { if (_isClosed) { return; } int endCommandIndex = line.IndexOf(_exitMessagePrefix); if (endCommandIndex >= 0) { if (Interlocked.CompareExchange(ref _firedOnExit, 1, 0) == 0) { string exitCode = SplitExitCode(line, endCommandIndex + _exitMessagePrefix.Length); _callback.OnExit(exitCode); } Close(); return; } if (!_beginReceived) { if (line.Contains(_beginMessage)) { _beginReceived = true; } continue; } _callback.OnOutputLine(line); } }
internal void Start(string commandText) { _command = _remoteSystem.CreateStreamableCommand(commandText); _remoteSystem.StartCommand(_command, Timeout.InfiniteTimeSpan); _command.Finished += (sender, e) => _callback.OnExit(((NonHostedCommand)sender).ExitCode.ToString(CultureInfo.InvariantCulture)); _command.OutputReceived += (sender, e) => _callback.OnOutputLine(e.Output); _command.RedirectErrorOutputToOutput = true; _command.BeginOutputRead(); }
private void OnOutputReceived(object sender, OutputReceivedEventArgs e) { IEnumerable <string> linesToSend = null; lock (_lock) { if (string.IsNullOrEmpty(e.Output)) { return; } _lineBuffer.ProcessText(e.Output, out linesToSend); } foreach (string line in linesToSend) { if (_isClosed) { return; } if (line.Equals(_startCommand, StringComparison.Ordinal)) { // When logged in as root, shell sends a copy of stdin to stdout. // This ignores the shell command that was used to launch the debugger. continue; } int endCommandIndex = line.IndexOf(_exitMessagePrefix); if (endCommandIndex >= 0) { if (Interlocked.CompareExchange(ref _firedOnExit, 1, 0) == 0) { string exitCode = SplitExitCode(line, endCommandIndex + _exitMessagePrefix.Length); _callback.OnExit(exitCode); } Close(); return; } if (!_beginReceived) { if (line.Contains(_beginMessage)) { _beginReceived = true; } continue; } _callback.OnOutputLine(line); } }
internal void Start(string commandText) { if (!_remoteSystem.IsConnected) { _remoteSystem.Connect(_remoteSystem.ConnectionInfo); } if (_remoteSystem.IsConnected) { _command = _remoteSystem.Shell.ExecuteCommandAsynchronously(commandText, Timeout.Infinite); _command.Finished += (sender, e) => _callback.OnExit(((NonHostedCommand)sender).ExitCode.ToString(CultureInfo.InvariantCulture)); _command.OutputReceived += (sender, e) => _callback.OnOutputLine(e.Output); _command.RedirectErrorOutputToOutput = true; _command.BeginOutputRead(); } else { Debug.Fail("Remote System not connected."); } }