How to send "Space Key" as command.

0 votes
asked Jun 21, 2012 by Sajad Karim (200 points)
edited Jul 16, 2014

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
answered Jun 21, 2012 by Sajad Karim (200 points)
edited Jul 12, 2012

Issue resolved with VirtualShell

commented Jun 21, 2012 by Lukas Matyska (55,530 points)
edited Jul 12, 2012

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

commented Jun 22, 2012 by Sajad Karim (200 points)
edited Jun 22, 2012

Thanks Lukas,

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

commented Jun 22, 2012 by Lukas Matyska (55,530 points)
edited Jun 22, 2012

Of course, I am looking on it.

+1 vote
answered Jun 21, 2012 by Lukas Matyska (55,530 points)
edited Jul 12, 2012

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
answered Jul 16, 2014 by Pavel Matyska (12,440 points)
edited Jul 16, 2014

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

...