I'm writing a program in C# on my computer which should start a Python program on a remote Raspberry Pi. For the moment the Python code is just printing 'Hello'
every second. The program should run permanently. When I start this program from C#, I would like to have a visual feedback, if my program is running – I'd like to see the printed output like in PuTTY.
The following code works fine for a command like ls
. But for the reason that my Python program test.py
should not finish – I never get an output – I's stuck in a continuous loop.
How can I display the output in real-time?
Here's my code:
using Renci.SshNet;
static void Main(string[] args)
{
var ssh = new SshClient("rpi", 22, "pi", "password");
ssh.Connect();
var command = ssh.CreateCommand("python3 test.py");
var asyncExecute = command.BeginExecute();
while (true)
{
command.OutputStream.CopyTo(Console.OpenStandardOutput());
}
}