将提示输入发送到Diagnostics.Process

时间:2012-04-18 08:24:05

标签: c# input process

我目前正在解决从.net app启动外部工具的问题。 我有这部分代码:

proc.StartInfo = new ProcessStartInfo(_app, _args);
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

但是,在启动应用程序后,我得到一个错误的StandartError输出,确认答案为“输入y / n”。 我已经尝试在启动过程后立即通过标准输入输入“y”,但仍然会出现相同的错误。

 var standartInput = proc.StandardInput;
    standartInput.AutoFlush = true;
    standartInput.WriteLine("y");
    standartInput.Close();

我真的很感激任何帮助。感谢。

PS:PuTTY Secure Copy客户端 - 是我在代码中使用的外部应用程序。当第一次运行应用程序以在系统注册表中保存服务器指纹时,有一个确认提示。

1 个答案:

答案 0 :(得分:0)

代码看起来不错。也许你在写“y”之前需要睡一会儿等。我想这个程序需要一点时间来询问用户输入