繁体   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