There is a long running script script.sh
on a remote Linux machine. I need to start it and monitor it's activity in real time. The script during it's activity may output to stdout
and stderr
. I am searching for a way to capture both of the streams.
I use Renci SSH.NET to upload script.sh
and start it, so it would be great to see a solution bounded to this library. In my mind the perfect solution is the 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();
}
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…