Some programs, like Python, may buffer the output, when executed this way. TextBox1.AppendText(line + Environment.NewLine))) įor a slightly different approach, see a similar WPF question: SSH.NET real-time command output monitoring. While (!result.IsCompleted || !reader.EndOfStream) ![]() Var cmd = client.CreateCommand("command1 command2") Ĭmd.OutputStream, Encoding.UTF8, true, 1024, true)) If not, use separate CreateCommand calls. If the command2 depend on an environment modified by command1, Using (var client = new SshClient(host, username, password)) To feed the output to a TextBox, just keep reading the stream on a background thread: private void button1_Click(object sender, EventArgs e) Use "exec" channel ( CreateCommand or RunCommand in SSH.NET). This command takes along time to be executed and no result appeared on the result text box.įirst, do not use "shell" channel to automate a command execution, unless you have a good reason. StrAnswer.AppendLine(ReadStream(reader)) StringBuilder strAnswer = new StringBuilder() Private static string SendCommand(ShellStream stream, string customCMD) While ((line = reader.ReadLine()) != null) StringBuilder result = new StringBuilder() Private static string ReadStream(StreamReader reader) Private static void WriteStream(string cmd, StreamWriter writer, ShellStream stream) ResultTxt.Text = SSHCommand.SendCommand(stream, "wget & sh cwp-latest") ShellStream stream = sshclient.CreateShellStream("customCommand", 80, 24, 800, 600, 1024) Using the following code SshClient sshclient = new SshClient(IPtxtBox.Text, UserNameTxt.Text, PasswordTxt.Text) Is there any way to execute Linux command and display the result in text box in Windows application like PuTTY.įor example I'm trying to execute the following commands wget
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |