This project is read-only.

shellstream errors

Mar 18, 2012 at 2:30 PM

hi,

 

when i create a shellstream and send commands,  how am i supposed to tell when a command has been executed successfully?

thanks

Damo

 

using System;
using System.IO;
using System.Threading;
using Renci.SshNet;
 
namespace ConsoleApplications
{
    public class Program
    {
        private static System.ComponentModel.IContainer components;
 
        private static void Main(string[] args)
        {
            using (var client = new SshClient(host, "admin", "abc"))
            {
                client.Connect();
 
                using (var stream = client.CreateShellStream("dumb", 80, 24, 800, 600, 1024))
                {
                    var reader = new StreamReader(stream);
                    var writer = new StreamWriter(stream);
                    writer.AutoFlush = true;
 
                    while (stream.Length == 0)
                    {
                        Thread.Sleep(500);
                    }
                    ReadStream(reader);
 
                    WriteStream("show run", writer, stream);
                    ReadStream(reader);
 
                    WriteStream("show ver", writer, stream);
                    ReadStream(reader);
                }
 
                client.Disconnect();
            }
        }
 
        private static void ReadStream(StreamReader reader)
        {
            string line = reader.ReadLine();
            while (line != null)
            {
                Console.WriteLine(line);
                line = reader.ReadLine();
            }
        }
 
        private static void WriteStream(string cmd, StreamWriter writer, ShellStream stream)
        {
            writer.WriteLine(cmd);
            while (stream.Length == 0)
            {
                Thread.Sleep(500);
            }
        }
    }
}

Coordinator
Mar 19, 2012 at 1:37 PM

Hi,

 

Unfortunately in shell stream environment I don't know how it would be possible :(.

 

Thanks,

Oleg

Mar 20, 2012 at 12:40 AM

reader.expect("ssh prompt")