2

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 の出力をキャプチャする方法が必要です。

4

1 に答える 1

2

plink.exe の要点は、PuTTY にコマンドライン インターフェイスを提供することです。それはあなたが使用することになっているものです。

于 2013-08-05T10:56:19.907 に答える