Commands are redisplayed before results are shown

Dec 5, 2014 at 7:38 PM
When I run a command like "show vlan" I always get the following before the results are shown (and not exactly as I typed it). I'm using SignalR btw.
 ssh> show vlan
I just want to see the results of the command and not a jumbled display of the command. Here is a source snippet:
                shellStream = client.CreateShellStream(@"xterm", 80, 25, 640, 480, 1024);
                SshSteams.GetOrAdd("foo", shellStream);
                shellStream.DataReceived += StartAsyncRead;
                shellStream.Write(command + "\n");

    private void StartAsyncRead(object sender, EventArgs e)
        ShellStream shellStream;
            if (!SshSteams.TryGetValue("foo", out shellStream))
                Clients.All.receive("ERROR: ShellStream object not found");

            shellStream.BeginRead(_data, 0, _data.Length, OnReadCompletion, new MyAsyncInfo(_data, shellStream));
        catch (Exception)

    private void OnReadCompletion(IAsyncResult ar)
        SshClient client;

        if (!SshClients.TryGetValue("foo", out client)) 
            Clients.All.receive("ERROR: connection object not found");

            var mai = (MyAsyncInfo)ar.AsyncState;
            int datalen = mai.Stream.EndRead(ar);
            string line = client.ConnectionInfo.Encoding.GetString(mai.ByteArray, 0, datalen);
        catch (Exception exception)
Dec 5, 2014 at 8:19 PM
It is a normal behavior of a terminal that the server send you back the entered text. Normally a terminal only displays the data received by the server.
I guess the problem you have is that you have to handle the xterm protocol.
Here you have a good overview of the xterm protocol:

Have you tried to executre commands with the SshCommand class? This is normally much easier.
Dec 5, 2014 at 9:26 PM
Ok, this is really getting frustrating. I've used the SshCommand class prevoiusly and had problems (see so I was told to use ShellStream. Now ShellStream is returning funny results and I'm told it's normal behavior (the SshCommand that did work did not return the jumbled mess). I may just have to tell my client that this cannot be done and look for a 3rd party solution.
Dec 5, 2014 at 9:52 PM
what kind of server do you have?
It looks like you have not a linux server.
Dec 6, 2014 at 8:15 AM
Please clarify the goal of your project. It gets quite confusing for us.
One day its a ubuntu server, now its a cisco device (?).

Are you sure, you are just showing what the server replies?

All I told you is that ShellStreams keep their environment while SshCommand doesn't.

I understand your frustration, been there done that :)
It's a very difficult task! So please clarify your goal and I'm sure we can help you.
Dec 8, 2014 at 1:17 PM
My goal is this. We want to create a SSH Web Client that can run on an locked down intranet site. This web client will be used remotely by system engineers when they cannot be physically in the office. The project I've put together is using MVC5 project and SignalR for communication between the web client and the server. If it's useful I've put together. Any assistance with this would be greatly appreciated.
Dec 8, 2014 at 2:11 PM
Edited Dec 8, 2014 at 2:14 PM
Thanks, now I understand I think.

What about using a finished solution like Shell in a Box?

Else I think you have to handle the Terminal Protocol, which is not part of SSH.NET.
Dec 8, 2014 at 3:11 PM
I would prefer not dealing with Linux (considering we are a Windows Server shop). I'll just keep going with this project and eventually get it sorted.
Dec 8, 2014 at 3:13 PM
We use Windows Servers (2008 and 2012)
Dec 8, 2014 at 3:42 PM
Since you develope a WebClient: What about handling the Stream Data via Javascript?

From shell in a box:


Would also make more sense, since the interactivity happens on the Client side.
You would just do the shell input/output handling with SSH.NET.