I seem to have run into a timing snag. When I start the session, the server sends me back 4 lines, the last of which being "login:". Then I need to enter the login with a newline, then wait for "Password", send the password, then wait for the prompt (identified by a ">" at the end). Here's my code
Telnet client = new Telnet("myserver");
VirtualTerminal terminal = new VirtualTerminal(120, 50);
if (terminal.Expect("login:", 1000))
if (terminal.Expect("Password:", 1000))
if (terminal.Expect(">:", 1000))
I never get into the first if, but if I dump the contents of the virtual terminal after the first if
(string content = terminal.Screen.GetRegionText(0, 0, terminal.Screen.Columns, terminal.Screen.Rows);)
then I see the "login:" I'm looking for. When I immediately send the login, then wait for "Password" - same story. So it seems that terminal.Expect only works from the point in time where it has been called... and if the server is fast enough and has already sent the expected string, Expect will fail.
As I will be running commands that take longer (and interactive operations where responses don't always come below my input but may update the existing lines - so using the Shell object is out of the question), I need to find a way to accommodate both. Is there a way to make Expect also consider what has already been received so I won't have to resort to the clumsy way of dumping the contents of the virtual terminal each time expect returns false?