The user name will be already submitted here:
processInfo.Arguments =
String.Format(@" {0} {1}:127.0.0.1:{2} -i {3} -l {4} {5}",
remoteOption, LocalPort, TargetPort, KeyPath, username, TargetIp);
So when you start the process, plink
will still handle the user name as input and return a line to process.StandardOutput
.
Now it waits for the password but don't ends the line, so string s = output.ReadLine();
dismatchs the real output the program submits.
Try instead reading each byte of the output:
var buffer = new char[1];
while (output.Read(buffer, 0, 1) > 0)
{
Console.Write(new string(buffer));
};
This will catch also the CR+LFs, so you don't have to mention, if the output have to add a new line.
If you want to handle CR+LFs manually (espec. parsing a specific line) you can add the buffer to a string, and only send it, if you find a "\r"
or a ":"
or so like:
var buffer = new char[1];
string line = "";
while (process.StandardError.Read(buffer, 0, 1) > 0)
{
line += new string(buffer);
if (line.Contains("\r\n") || (line.Contains("Passphrase for key") && line.Contains(":")))
{
Console.WriteLine(line.Replace("\r\n",""));
line = "";
}
};