我正在我的计算机上用 C# 编写一个程序,该程序应该在远程 Raspberry Pi 上启动 Python 程序。目前,Python 代码只是'Hello'每秒打印一次。该程序应该永久运行。当我从 C# 启动此程序时,如果我的程序正在运行,我希望获得视觉反馈 - 我希望看到像 PuTTY 中一样的打印输出。
以下代码适用于类似 的命令ls。但由于我的 Python 程序test.py无法完成——我从未得到输出——我陷入了连续循环。
如何实时显示输出?
这是我的代码:
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());
}
}
回首忆惘然
至尊宝的传说
相关分类