【发布时间】:2009-11-05 21:03:36
【问题描述】:
我正在尝试使用 StandardInput 和 StandardOutput 围绕控制台应用程序进行包装。我在控制台应用程序提示输入密码的地方卡住了。
我想从 StandardOutput 读取数据,使用读取的文本提示用户,然后使用 StandardInput 将用户的输入写回控制台应用程序。看起来很简单,这是我目前拥有的:
Process process = new Process()
{
StartInfo =
{
FileName = "bin\\vpnc.exe",
Arguments = "--no-detach --debug 0",
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardOutput = true,
}
};
process.OutputDataReceived += (s, args) =>
{
textBlock1.Dispatcher.Invoke(new Action(() =>
{
textBlock1.Text += args.Data;
}));
};
process.Start();
process.BeginOutputReadLine();
问题是BeginOutputReadLine() 正在这样做...等待一行结束。在这种情况下,它只是坐着,坐着,再坐着,因为没有要读取的行……控制台应用程序写出了没有行尾的文本,正在等待输入。 巧合的是,当我手动终止进程时,事件触发并得到文本。
有没有办法告诉进程正在等待标准输入?还是我错过了实现目标的完全明显的方法?
【问题讨论】:
标签: c# scripting process console