私はc#のplinkを使用してLinuxサーバーに接続し、いくつかのプログラムを実行しています。c#コンソールプログラムとplink.exeの両方が同じWindowsマシン上にあります。
問題は、Linuxサーバーに初めて接続するときに、plinkがLinuxサーバーからのSSHキーを受け入れて保存するかどうかを尋ねてくることです。すべてのサーバーが私のLANにあり、セキュリティの問題がないため、私は常にこれに「はい」と答えたいと思います。
私はc#プロセスタイプを使用しています。正しい引数をplinkに渡し、出力をリダイレクトして開始します。ここで問題となるのは、plinkがプロンプトを表示するとき、process.StandardOutput.ReadToEnd();です。ハングし、plinkによってキーを受け入れるように求められたのか、実際にLinuxサーバーにログインしたのかを判断する方法がありません。
string output = string.Empty;
string error = string.Empty;
string arguments = @" -ssh -pw password root@12.12.12.12 ./Install_xxx.bin";
using (Process process = new Process())
{
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "plink";
psi.Arguments = arguments;
psi.ErrorDialog = false;
psi.UseShellExecute = false;
psi.RedirectStandardError = true;
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = true;
psi.CreateNoWindow = true;
process.StartInfo = psi;
process.Start();
output = process.StandardOutput.ReadToEnd();
error = process.StandardError.ReadToEnd();
}
ありがとう