I wish to know how to read the output from putty.exe console window.
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.
FYI this is what i have now; changing the string 'putty.exe' to 'cmd.exe' make things work:
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();
}
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.