簡體   English   中英

在C#中使用膩子關閉Linux

[英]Using putty to shutdown linux in c#

在將應用程序從C#中的Windows編寫為關閉/重啟Linux的過程中,我遇到了一些問題。

我正在嘗試使用膩子執行此任務,但是出了點問題。

            Process p = new Process();
            ProcessStartInfo info = new ProcessStartInfo();
            info.FileName = "putty.exe";
            info.RedirectStandardInput = true;
            info.UseShellExecute = false;
            info.Arguments = @"root@192.168.0.25 -pw 1234qwer ";

            p.StartInfo = info;
            p.Start();

            p.StandardInput.WriteLine("shutdown -h ");
            p.StandardInput.WriteLine("exit");
            string output = p.StandardOutput.ReadToEnd();
            p.WaitForExit();
            Console.WriteLine(output);

在上面,我粘貼了用於實現此目標的代碼。 在我必須在膩子命令行中編寫更多內容之前,一切都很好,在這種情況下,StandardInput並不是實現此目的的好方法,而且我也沒有找到其他實現此目的的方法。

我也嘗試以相同的方式使用PLINK.exe,但它也不能解決我的問題-實際上,PLINK甚至沒有顯示出來。

解決這個問題的任何想法或技巧都很好。

嘗試SSH.NET

using (var client = new SshClient("hostnameOrIp", "username", "password"))
{
    client.Connect();
    client.RunCommand("shutdown -h now;systemctl poweroff");
    client.Disconnect();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM