我有一个ssh进入Unix服务器的进程。如果给出错误的凭据,我试图获得此过程的标准输出。在这种情况下,程序等待用户输入正确的密码(表示作为参数给出的密码无效)。预期的结果是以下字符串:
Using keyboard-interactive authentication.
Password:
我知道这是预期的,因为我已经将标准输出传送到文件,在命令行中运行程序。但是,我遇到了一个问题,无论出于何种原因,标准输出只会给我第一行,然后挂起。它打印出Using keyboard-interactive authentication
,但没有到达Password:
这是我的代码:
Dim stdOutput = New StringBuilder()
Public Sub startProcess(processName As String, id As String, unixServer As String, pw As String)
Dim process As Process = New Process()
process.StartInfo.FileName = processName
process.StartInfo.Arguments = "-ssh " & id & "@" & unixServer & " -pw " & pw
process.StartInfo.UseShellExecute = False
process.StartInfo.CreateNoWindow = True
process.StartInfo.RedirectStandardOutput = True
AddHandler process.OutputDataRecieved, AddressOf outputHandler
process.Start()
process.BeginOutputReadLine()
'Wait for 3 seconds to give the process a chance to get the standard output
process.WaitForExit(3000)
Console.WriteLine(stdOutput.ToString())
End Sub
Public Sub outputHandler(process As Object, outline As DataReceivedEventArgs)
stdOutput.Append(outline.Data)
End Sub
这只会打印出Using keyboard-interactive authentication.
,但不会打印出来Password:
感谢任何帮助。