0 votes
by (200 points)
edited

I am using Rebex's Shell class and I have successfully logged into the terminal and have set prompt.

Issue is, I want to run a command which requires user interaction, I am getting its 1st page output but for 2nd page it's prompting to press "space key" (--type q to quit or space key to continue--)

I have tried following lines but getting error: "Unable to process command."

ConsoleKeyInfo key = new ConsoleKeyInfo('x20', ConsoleKey.Spacebar, false, false, false); m_Shell.SendCommand(key.KeyChar.ToString());

Please can any one help me in this regard.

Thanks in advance.

3 Answers

0 votes
by (200 points)
edited

Issue resolved with VirtualShell

by (72.7k points)
edited

Oh, you were a bit quicker than me to resolve your issue. Great!

by (200 points)
edited

Thanks Lukas,

I have place another query related to timeOut. Please could you answer. Thanks in advance.

by (72.7k points)
edited

Of course, I am looking on it.

+1 vote
by (72.7k points)
edited

Unfortunately, the Shell class is not able to handle your case. Please try our experimental VirtualShell class, which provides such functionality.

You can use it like this:

// initialize Telnet shell
Telnet telnet = new Telnet("server");
VirtualShell shell = new VirtualShell(telnet.StartVirtualTerminal());

// set prompt
shell.Prompt = "username[@].*[$] ";

// login
shell.Expect("[Ll]ogin: ");
shell.SendCommand("username");
shell.Expect("[Pp]assword: ");
shell.SendCommand("password");

// read welcome message
Console.WriteLine("Welcome message:");
Console.WriteLine(shell.ReadAll());

// send a multipage command
Console.WriteLine("ls -la / | more:");
shell.SendCommand("ls -la / | more");

// receive the first page
Console.WriteLine("Page1:");
Console.WriteLine(shell.Expect("--More--"));

// send only the <space> to the server
shell.Terminal.SendToServer(" ");

// recieve the rest data
Console.WriteLine("Page2:");
Console.WriteLine(shell.ReadAll());

Usually you don't know how many pages you will receive. You would do something like this:

...
shell.SendCommand("ls -la / | more");

string received;
int page = 1;
int match;
do
{
    // wait for Prompt or "--More--"
    match = shell.Expect(out received, shell.Prompt, "--More--");
    if (match < 0)
        throw new InvalidOperationException(
            "Neither the Prompt nor the expected regex was received within the Timeout limit.");

    // display received data
    Console.WriteLine("Page{0}:", page++);
    Console.WriteLine(received);

    // if received "--More--", send <space> to the server
    if (match == 1)
        shell.Terminal.SendToServer(" ");

} while (match != 0);
0 votes
by (15.2k points)
edited

Hi, we have just release new Scripting API in 2014-R2 release. You can read more of its features on Scripting features page.

...