Hi,
I'm trying to use the ssh ShellStream in an asynchronous way, It's works pretty well except for one thing, the commands i'm sending are being written by my reader function, example:
u0_a113@android:/sdcard $ cd DCIM
cd DCIM
u0_a113@android:/sdcard/DCIM $ ls
ls
Camera
u0_a113@android:/sdcard/DCIM $
Is there "clean" way to fix this problem ?
I tried a lot of stuff such as lock but without any success.
I think it comes froms the Stream where the Stream reader sees the commands sent by the Stream writer.
Thanks,
Code:
I'm trying to use the ssh ShellStream in an asynchronous way, It's works pretty well except for one thing, the commands i'm sending are being written by my reader function, example:
u0_a113@android:/sdcard $ cd DCIM
cd DCIM
u0_a113@android:/sdcard/DCIM $ ls
ls
Camera
u0_a113@android:/sdcard/DCIM $
Is there "clean" way to fix this problem ?
I tried a lot of stuff such as lock but without any success.
I think it comes froms the Stream where the Stream reader sees the commands sent by the Stream writer.
Thanks,
Code:
using (var client = new SshClient(hostname, port, login,password))
{
client.Connect();
using (var stream = client.CreateShellStream("xterm", 80, 24, 800, 600, 1024))
{
StreamReader reader = new StreamReader(stream);
var writer = new StreamWriter(stream);
String cmd;
stream.DataReceived += _process_OutputDataReceived;
writer.AutoFlush = true;
while (!stream.CanWrite)
{
System.Threading.Thread.Sleep(100);
}
while (client.IsConnected)
{
cmd = Console.ReadLine();
cmd = cmd + '\n';
stream.Write(cmd);
}
}
client.Disconnect();
}
private void _process_OutputDataReceived(object sender, Common.ShellDataEventArgs e)
{
ShellStream stream = (ShellStream) sender;
StreamReader reader = new StreamReader(stream);
Console.Write(reader.ReadToEnd());
}