wpf - SSH.NET real-time command output monitoring -
there long running script script.sh on remote linux machine. need start , monitor it's activity in real time. script during it's activity may output stdout , stderr. searching way capture both of streams.
i use renci ssh.net upload script.sh , start it, great see solution bounded library. in mind perfect solution new method:
var realtimescreen= ...; var commandexecutionstatus = sshclient.runcommandasync( command: './script.sh', stdouteventhandler: stdoutstring => realtimescreen.updatestdout(stdstring) stderreventhandler: stderrstring => realtimescreen.updatestderr(stderrstring)); ... commandexecutionstatus.continuewith(monitoringtask => { if (monitoringtask.completed) { realtimescreen.finish(); } });
use sshclient.createcommand method. returns sshcommand instance.
the sshcommand class has extendedoutputstream property returns stream both stdout , stderr.
see sshcommandtest.cs:
public void test_execute_extendedoutputstream() { var host = resources.host; var username = resources.username; var password = resources.password; using (var client = new sshclient(host, username, password)) { #region example sshcommand createcommand execute extendedoutputstream client.connect(); var cmd = client.createcommand("echo 12345; echo 654321 >&2"); var result = cmd.execute(); console.write(result); var reader = new streamreader(cmd.extendedoutputstream); console.writeline("debug:"); console.write(reader.readtoend()); client.disconnect(); #endregion assert.inconclusive(); } }
Comments
Post a Comment