【问题标题】:Running a Daemon remotely and in the background of Desktop Application在桌面应用程序的后台远程运行守护程序
【发布时间】:2020-06-12 03:48:57
【问题描述】:

我想制作一个 GUI,用于启动和停止远程 Linux 服务器上的脚本。我已经使用 SSH.NET 成功地通过 SSH 连接到远程服务器,并且可以成功运行脚本。然而,由于远程脚本还没有完成,整个程序就停止了。 (这个脚本不应该完成,实际上是监控行为)。我希望能够通过按下一个按钮来停止脚本,该按钮将对该脚本进程执行停止命令。我想我可能需要使用“&”命令在桌面应用程序和 Linux 服务器上设置多个线程才能发生这种情况。

任何帮助将不胜感激!

代码如下:

private void StartButton_Click(object sender, RoutedEventArgs e)
     {
         isPBXMonitoringEnabled = true;

         using (SshClient ssh = new SshClient("server", "uname", "pw"))
         {
             ssh.Connect();

             var cmd = ssh.CreateCommand("./phpScripts/script.php");


             var asynch = cmd.BeginExecute();

             var reader = new StreamReader(cmd.OutputStream);

             while (!asynch.IsCompleted) ///This wont complete... I need to find a way to allow this to go on but take in a command to stop it when i need to.
             {
                 var result = reader.ReadLine();
                 if (string.IsNullOrEmpty(result))
                     continue;
                 Console.Write(result);
             }
             cmd.EndExecute(asynch);


             ssh.Disconnect();
         }



     }

【问题讨论】:

    标签: c# linux ssh ssh.net


    【解决方案1】:

    听起来你知道答案。一旦应用程序启动了远程进程,您需要另一个线程来发送退出命令。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-19
      • 1970-01-01
      • 1970-01-01
      • 2023-03-10
      • 2011-03-27
      • 1970-01-01
      • 2015-06-08
      • 1970-01-01
      相关资源
      最近更新 更多