gpt4 book ai didi

c# - 如何在调用 Process.start 方法后向 '.exe' 文件提供第二个输入?

转载 作者:行者123 更新时间:2023-11-30 20:21:50 27 4
gpt4 key购买 nike

我必须执行一个“.exe”文件,它会产生一个输出并再次请求另一个输入。我能够运行第一部分,但无法传递第二个参数来完成该过程。

这是我的代码:

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = @"C:\Context.exe";
startInfo.Arguments = "xyz";
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
Process.Start(startInfo);

最佳答案

我会使用 StandardInput连同RedirectStandardInput .您可以使用此 StandardInput StreamWriter 对象传递用户将在命令行上输入的任何数据。如果此应用程序有用户界面,您可能需要完全做其他事情。

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = @"C:\Context.exe";
startInfo.Arguments = "xyz";
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
startInfo.RedirectStandardInput = true;
var p = Process.Start(startInfo);

// Write whatever data you need to send to the application here.
p.StandardInput.Write("y");

关于c# - 如何在调用 Process.start 方法后向 '.exe' 文件提供第二个输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32995256/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com