title: How to read Putty.exe (but not plink.exe) output in C#?
body: <p>I wish to know how to read the output from putty.exe console window.</p>
  
  <p>There are plenty of answers about how to get the output (and how to input) for plink.exe/cmd.exe, yet none of them work for putty.exe.</p>
  
  <p>FYI this is what i have now; changing the string 'putty.exe' to 'cmd.exe' make things work:</p>
  
  <pre><code>            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) =&gt;
                  {
                      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();
              }
  </code></pre>
  
  <p>Edited:
  The purpose to the piece of code is to automatically handle the login process: after username/password are provided, enter 'sudo' and input corresponding auditing messages.
  I need a way to capture the output of putty.exe so that I could input texts to this terminal.</p>