简体   繁体   English

将提示输入发送到Diagnostics.Process

[英]Send prompt input to Diagnostics.Process

I'm currently solving a problem of starting external tool from .net app. 我目前正在解决从.net应用启动外部工具的问题。 I have this part of code: 我有这部分代码:

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;

But, after starting application I get an error to StandartError output witn promt confirmation answer "enter y/n". 但是,启动应用程序后,我收到StandartError输出错误并提示确认输入“是/否”。 I've already tried to input "y" via standart input, right after starting process, but still get the same error. 我已经尝试在启动过程之后立即通过标准输入输入“ y”,但是仍然会遇到相同的错误。

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

I'd really appreciate any help. 我真的很感谢您的帮助。 Thanks. 谢谢。

PS: PuTTY Secure Copy client - is the external app I'm using from code. PS:PuTTY Secure Copy客户端-是我从代码中使用的外部应用程序。 There is a confirmation promt, when running app for first time to save servers fingerprint in system registry. 首次运行应用程序时,有一个确认提示将服务器指纹保存在系统注册表中。

The code looks OK to me. 该代码在我看来还可以。 Maybe you need to sleep for a second or something before writing the "y". 在写“ y”之前,您可能需要睡一秒钟左右。 I would imagine that the program takes a little while to ask the user for input 我可以想象该程序需要一些时间来询问用户输入

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Diagnostics.Process - 转储输出到文件 - Diagnostics.Process - Dump output to file 防止Diagnostics.Process在完成后关闭 - Prevent Diagnostics.Process to close after finish Diagnostics.Process的替代品,可运行简单的shell命令! - Alternatives to Diagnostics.Process to run a simple shell command! 当 Webform 应用程序从 IIS 运行时,Diagnostics.Process 启动功能不起作用 - Diagnostics.Process start function not working when webform application run from IIS PSExec:将C#控制台应用程序输出重定向到window / Diagnostics.Process? - PSExec: Redirecting C# console app output to window/Diagnostics.Process? Diagnostics.Process不使用adobe reader打开PDF文件 - Diagnostics.Process doesn't open PDF file using adobe reader C#通过命令提示符将输入发送到单独的进程 - C# Send input to separate process through command prompt 使用命令提示符和System.Diagnostics.Process从asp.net页面重新启动Windows - Restart windows from asp.net page using command prompt and System.Diagnostics.Process 使用System.Diagnostics.Process运行vb脚本,但只能部分成功地将输入文本输入到进程的stdin中 - Run a vb script using System.Diagnostics.Process but only partially successful in feeding in input text to the process' stdin 系统.诊断.过程问题 - System.Diagnostics.Process Issue
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM