【发布时间】:2013-05-17 04:05:27
【问题描述】:
我正在启动一个进程并使用 plink 创建一个反向隧道到我本地网络中的 ssh。
我可以很好地连接到服务器,但它没有在控制台窗口上显示全部内容,我的目标是等待所有内容显示,然后使用 process.standardInput 输入密码继续。
我应该在控制台窗口上收到这个:
Using username "dayan".
Passphrase for key "rsa-key-20130516":
但我只收到第一行:
Using username "dayan".
如果我按下回车键,它确实会为我提供“密码错误”,但我从未看到 “密钥 rsa-key 的密码......”
另外请注意,我确实输入了正确的密码,控制台仍然空白,但是在包含 SSH 服务器的 Linux shell 上,我运行了 who 命令并注意到我已成功连接。
这可能是什么问题?
ProcessStartInfo processInfo = new ProcessStartInfo();
processInfo.FileName = Path.Combine(BinPath, "plink.exe");
processInfo.Arguments =
String.Format(@" {0} {1}:127.0.0.1:{2} -i {3} -l {4} {5}",
remoteOption, LocalPort, TargetPort, KeyPath, username, TargetIp);
processInfo.UseShellExecute = false;
processInfo.CreateNoWindow = false;
processInfo.RedirectStandardOutput = true;
processInfo.RedirectStandardInput = true;
processInfo.RedirectStandardError = true;
Process process = Process.Start(processInfo);
StreamReader output = process.StandardOutput;
while (!output.EndOfStream) {
string s = output.ReadLine();
if (s != "")
Console.WriteLine(s);
}
process.WaitForExit();
process.Close();
【问题讨论】: