Is there any way to execute Linux command and display the result in text box in Windows application like PuTTY.
For example I'm trying to execute the following commands
wget http://centos-webpanel.com/cwp-latest
sh cwp-latest
using the following code
SshClient sshclient = new SshClient(IPtxtBox.Text, UserNameTxt.Text, PasswordTxt.Text);
sshclient.Connect();
ShellStream stream = sshclient.CreateShellStream("customCommand", 80, 24, 800, 600, 1024);
resultTxt.Text = SSHCommand.SendCommand(stream, "wget http://centos-webpanel.com/cwp-latest && sh cwp-latest");
private static void WriteStream(string cmd, StreamWriter writer, ShellStream stream)
{
writer.WriteLine(cmd);
while (stream.Length == 0)
Thread.Sleep(500);
}
private static string ReadStream(StreamReader reader)
{
StringBuilder result = new StringBuilder();
string line;
while ((line = reader.ReadLine()) != null)
result.AppendLine(line);
return result.ToString();
}
private static string SendCommand(ShellStream stream, string customCMD)
{
StringBuilder strAnswer = new StringBuilder();
var reader = new StreamReader(stream);
var writer = new StreamWriter(stream);
writer.AutoFlush = true;
WriteStream(customCMD, writer, stream);
strAnswer.AppendLine(ReadStream(reader));
string answer = strAnswer.ToString();
return answer.Trim();
}
This command takes along time to be executed and no result appeared on the result text box.