This project is read-only.

ExpectAction Problem

May 19, 2013 at 3:28 PM
Is it correct to assume that only two "choice" can be used in an ExpectAction?

I'm trying to issue a traceroute command on a cisco router without the host specified. This causes the CLI to ask for additional information, including target and source host. A total of 10 questions are asked before the command is successfully executed.

I thought I could just chain ExpectActions as so:
 ss.Expect(
                            new ExpectAction(@"Protocol \[ip\]: ", (s) =>
                                {
                                    ss.WriteLine("ip");
                                    _reply += s;
                                }),
                            new ExpectAction(@"Target IP address: ", (s) =>
                                {
                                    ss.WriteLine(dIpAddress);
                                    _reply += s;
                                }),
                            new ExpectAction(@"Source address: ", (s) =>
                                {
                                    ss.WriteLine(sIpAddress);
                                    _reply += s;
                                }),
                            new ExpectAction(@"Numeric display \[n\]: ", (s) =>
                                {
                                    ss.WriteLine("n");
                                    _reply += s;
                                }),
                            new ExpectAction(@"Timeout in seconds [3]: ", (s) =>
                                {
                                    ss.WriteLine("3");
                                    _reply += s;
                                }),
                            new ExpectAction(@"Probe count [3]: ", (s) =>
                                {
                                    ss.WriteLine("3");
                                    _reply += s;
                                }),
                            new ExpectAction(@"Minimum Time to Live [1]: ", (s) =>
                                {
                                    ss.WriteLine("1");
                                    _reply += s;
                                }),
                            new ExpectAction(@"Maximum Time to Live [30]: ", (s) =>
                                {
                                    ss.WriteLine("30");
                                    _reply += s;
                                }),
                            new ExpectAction(@"Port Number [33434]: ", (s) =>
                                {
                                    ss.WriteLine("33434");
                                    _reply += s;
                                }),
                            new ExpectAction(@"Loose, Strict, Record, Timestamp, Verbose[none]: ", (s) =>
                                {
                                    ss.WriteLine(" ");
                                    _reply += s;
                                }),
                            new ExpectAction(new Regex(@"\\*  \\*  \\*"), (s) =>
                                {
                                    _reply = s;
                                    _reply += s;
                                })
                            );
However, only the first two are ever processed.

I assume I'm doing this wrong. I appreciate any input.
May 22, 2013 at 7:02 AM
Never mind, I found the issue that had been plaguing me.

The root cause of my problem was that I didn't realize that WriteLine was sending "\r\n". Cisco routers don't line the linefeed. This had worked with SharpSSH, but it was only sending "\r".

So I changed everything to Write and added the \r to my data. Now everything works.