나는 C#에서 plink를 사용하여 Linux 서버에 연결하고 일부 프로그램을 실행합니다. C# console 프로그램과 plink.exe는 모두 동일한 Windows 시스템에 있습니다.C#에서 plink의 캐시 키 질문에 yes로 응답하는 방법
문제는 리눅스 서버에 처음 연결할 때 plink가 Linux 서버에서 SSH 키를 수락하고 저장할지 묻습니다. 모든 서버가 LAN에 있고 보안 상 문제가 없기 때문에 항상 예라고 응답하고 싶습니다.
나는 C# 프로세스 유형을 사용하고 있으며 올바른 인수를 plink에 전달하고 출력을 리디렉션하고 시작합니다. 이제 plink가 프롬프트 할 때 문제가 발생합니다. process.StandardOutput.ReadToEnd(); 멈추고 plink가 키를 받아들이거나 실제로 리눅스 서버에 로그인했는지 여부를 알아낼 방법이 없습니다.
string output = string.Empty;
string error = string.Empty;
string arguments = @" -ssh -pw password [email protected] ./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();
}
감사
감사합니다 ... 비동기 메서드를 사용하기로 결정했습니다. – danze