0 votes
by (190 points)
edited

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?

by (62.7k points)
edited

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

by (190 points)
edited

StartShell(ShellMode.WellKnownShell);

2 Answers

0 votes
by (62.7k points)
edited
 
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);
by (190 points)
edited

ShellMode.Prompt fixed the issue. Thanks!

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.

...