SendCommand ReadAll and standard out/error

0 votes
asked Feb 29, 2012 by Brad_Kremer (190 points)
edited Jul 16, 2014

I'm connecting to an embedded unix target running BusyBox.

If I just start a Rebex.TerminalEmulation.SshTerminalControl, and issue the following command I get:

$ userlevel
3
OK
$

'3' is the response and the 'OK' is the standard error after it has completed. If I do the same thing programatically through a Rebex.TerminalEmulation.Shell.SendCommand, and then follow it with a ReadAll, I get:

"OK\n3\n"

This is not correct. I want it to respond

"3\nOK\n"

How can I prevent the standard error from returning first?

commented Feb 29, 2012 by Lukas Matyska (40,360 points)
edited Feb 29, 2012

Can you please provide which Rebex.TerminalEmulation.ShellMode have you used?

commented Feb 29, 2012 by Brad_Kremer (190 points)
edited Feb 29, 2012

StartShell(ShellMode.WellKnownShell);

2 Answers

0 votes
answered Mar 1, 2012 by Lukas Matyska (40,360 points)
edited Jul 12, 2012
 
Best answer

The ShellMode.WellKnownShell behaves slightly different than the TerminalControl. The output and error streams are merged in way, where it is not defined which data comes first. You can try to use the ShellMode.Prompt which is closer to the TerminalControl.

However, I suggest you to use our experimental VirtualShell class, which is more flexible. It can be used like follows:

string host = "...";
string username = "...";
string password = "...";

Ssh client = new Ssh();
client.Connect(host);
client.Login(username, password);

VirtualTerminal vt = client.StartVirtualTerminal();
VirtualShell shell = new VirtualShell(vt);

string prompt = username + "[@].*[$] $";

string welcome = shell.Expect(prompt);
Console.WriteLine("Welcome message:");
Console.WriteLine(welcome);

shell.SendCommand("dir");

string response = shell.Expect(prompt);
Console.WriteLine("Command output:");
Console.WriteLine(response);
commented Mar 5, 2012 by Brad_Kremer (190 points)
edited Mar 5, 2012

ShellMode.Prompt fixed the issue. Thanks!

0 votes
answered Jul 16, 2014 by Pavel Matyska (9,740 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.

...