Hello, I have a problem with the "ReadUntilPrompt" function.
Test Environment.
Client libs:
- Rebex.Terminal 1.0.5605.1
- Rebex.SshShell 1.0.5605.1
Target hosts:
- Linux (CentOS, Red Hat, Ubuntu, Debian, OpenSUSE etc.) - any Linux with any version.
- VMware ESXi - version 6.0.0, other versions not tested.
Code Example #1:
var client = new Ssh();
client.Connect(host, port);
client.Login(user, password);
var shell = client.StartScripting();
shell.WaitFor(Rebex.TerminalEmulation.ScriptEvent.AnyText);
shell.DetectPrompt();
shell.SendCommand("echo abcdefghijklmnopqrstuvwxyz01234567890123456789abcdefghijklmnopqrstuvwxyz")
var response = shell.ReadUntilPrompt();
shell.Close();
client.Disconnect();
client.Dispose();
Result:
Linux returns
"abcdefghijklmnopqrstuvwxyz01234567890123456789abcdefghijklmnopqrstuvwxyz\r\n".
It's correct.
But VMware ESXi returns "pqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz01234567890123456789abcdefghijklmnopqrstuvwxyz\r\n".
VMware ESXi response has first 15 unnecessary chars - "pqrstuvwxyz\r\n".
That is the problem!
Modifying the example code.
Code Example #2:
var client = new Ssh();
client.Connect(host, port);
client.Login(user, password);
var shell = client.StartScripting();
shell.WaitFor(Rebex.TerminalEmulation.ScriptEvent.AnyText);
shell.DetectPrompt();
shell.Send("echo abcdefghijklmnopqrstuvwxyz01234567890123456789abcdefghijklmnopqrstuvwxyz");
shell.Send(FunctionKey.Enter);
var response = shell.ReadUntil(ScriptEvent.Duration(5000));
shell.Close();
client.Disconnect();
client.Dispose();
Result:
VMware ESXi returns "echo abcdefghijklmnopqrstuvwxyz01234567890123456789abcdefghijklmno\r\r\npqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz01234567890123456789abcdefghijklmnopqrstuvwxyz\r\n[root@esxi:~] ", where:
- "[root@esxi:~] " - first 14 chars are prompt, not present in response.
- "echo abcdefghijklmnopqrstuvwxyz01234567890123456789abcdefghijklmno" - 66 chars, first part of the input command.
14 + 66 = 80 is equals to virtual terminal columns number default value.
- "\r\r\n" - 3 chars, virtual terminal wrap line delimiter?
- "pqrstuvwxyz" - 11 chars, last part of the input command.
- the command output.
I suppose, that while response is contain the "\r\r\n", the function ReadUntilPrompt can't determine correctly where the command output is started.
I can increase the virtual terminal columns number value, but 1024 is a max value and is not enough for one line shell scripts. Also the sample code works perfectly on any Linux system without modyifing default value.