/// <summary> /// Move through everything in the input stream until it looks like we are looking at a prompt. /// </summary> /// <param name="shell"></param> public static async Task <string> WaitTillPromptText(this ShellStream shell) { const int promptTimeout = 20; var timeout = DateTime.Now + TimeSpan.FromSeconds(promptTimeout); var allText = new StringBuilder(); while (true) { while (shell.Length == 0 && timeout > DateTime.Now) { await Task.Delay(10); } if (shell.Length == 0) { throw new NoLinuxShellPromptSeenException($"It could be that the remote machine isn't responding - didn't get anything that looked like a prompt in {promptTimeout} seconds"); } string line; while ((line = await shell.ReadLineAsync(TimeSpan.FromMilliseconds(10))) != null) { //Trace.WriteLine("WaitTillPromptText: read text: " + line, "SSHConnection"); allText.AppendLine(line); } if (shell.Length > 0) { return(allText.ToString()); } } }