Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在C#中读取Putty.exe(而不是plink.exe)输出?_C#_Putty - Fatal编程技术网

如何在C#中读取Putty.exe(而不是plink.exe)输出?

如何在C#中读取Putty.exe(而不是plink.exe)输出?,c#,putty,C#,Putty,我想知道如何从putty.exe控制台窗口读取输出 关于如何获取plink.exe/cmd.exe的输出(以及如何输入),有很多答案,但没有一个适用于putty.exe 仅供参考,这就是我现在拥有的;将字符串“putty.exe”更改为“cmd.exe”可以使事情正常进行: var process = new Process(); process.StartInfo.RedirectStandardOutput = true;

我想知道如何从putty.exe控制台窗口读取输出

关于如何获取plink.exe/cmd.exe的输出(以及如何输入),有很多答案,但没有一个适用于putty.exe

仅供参考,这就是我现在拥有的;将字符串“putty.exe”更改为“cmd.exe”可以使事情正常进行:

            var process = new Process();
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardInput = true;
            process.StartInfo.RedirectStandardError = true;
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.FileName = "putty.exe";
            process.OutputDataReceived +=
                (s, e) =>
                {
                    Console.WriteLine(e.Data);
                    switch (e.Data)
                    {
                        case "test1":
                            {
                                process.StandardInput.WriteLine("echo test2");
                            }
                            break;

                        case "test2":
                            {
                                process.StandardInput.WriteLine("exit");
                            }
                            break;
                    }
                };

            if (process.Start())
            {
                process.BeginErrorReadLine();
                process.BeginOutputReadLine();
                process.StandardInput.WriteLine("echo test1");
                process.WaitForExit();
            }
编辑: 这段代码的目的是自动处理登录过程:在提供用户名/密码后,输入“sudo”并输入相应的审核消息。
我需要一种方法来捕获putty.exe的输出,这样我就可以将文本输入到这个终端。

plink.exe的整个要点就是为putty提供一个命令行界面。这就是你应该使用的。

为什么不使用sshnet.codeplex.com呢?也许你应该试着解释一下为什么你想阅读PuTTY输出而不是plink。@MartinPrikryl PuTTY似乎更适合交互使用,因为我们不是将其用于自动作业。PuTTY似乎更适合交互使用,因为我们不是将其用于自动作业乔布斯。此外,团队决定通过cmd.exeSo使用putty.exe而不是plink.exe,您是否在自动化?也许如果你添加你想要完成的,我们可以更好地帮助你。嗨,基本上我只想自动化登录和审核过程;最终用户将进入终端并执行任何进一步的操作。是的,您正在尝试在圆孔中安装一个圆形和方形的销钉。我建议在服务器端使用私钥进行身份验证和审核,以实现自动化。不过,这是另一个问题的主题。您好,Hometoast,您能帮助我在C#中自动化unix命令吗?使用plink,我尝试了plink,但无法继续。请参阅此链接中的问题