C# 如何模拟;按“回车键”;在后台工作?

C# 如何模拟;按“回车键”;在后台工作?,c#,process,C#,Process,在我的可执行进程实例中,我有两行控制台.ReadLine行。如何通过过程中的Enter按键(用户模拟输入按键)InputStream类?enter键在输入字符串中的外观如何 // in string input I want to have information, that "user" pressed enter key this.Process.StandardInput.Write(input); 我的过程在后台工作,我已经设置了 this.Process.StartInfo.Us

在我的可执行
进程
实例中,我有两行
控制台.ReadLine
行。如何通过
过程中的
Enter按键
(用户模拟输入按键)InputStream
类?
enter
键在输入字符串中的外观如何

// in string input I want to have information, that "user" pressed enter key  
this.Process.StandardInput.Write(input);
我的过程在后台工作,我已经设置了

this.Process.StartInfo.UseShellExecute = false;
旗帜

编辑:

在我的
exe
文件中存在这样的代码:

   for (int i = 0; i < 3; i++)
   {
       array[i] = Console.ReadLine();
   }
for(int i=0;i<3;i++)
{
数组[i]=Console.ReadLine();
}

我想在我的
过程中模拟按enter键输入字符串。StandardInput.Write
你可以使用
WriteLine()

或者您可以手动编写换行符序列

this.Process.StandardInput.Write(this.Process.StandardInput.NewLine);
任意一种方式都将
AutoFlush
设置为true

this.Process.StandardInput.AutoFlush = true;
或在写入后手动刷新

this.Process.StandardInput.Flush();
如果你想一次发送更多的行,只需一次发送更多的换行,前面有你想要的文本

this.Process.StandardInput.Write(  "a" + this.Process.StandardInput.NewLine
                                 + "b" + this.Process.StandardInput.NewLine);

你能告诉我它将如何工作吗?因为当我有一个从预编译的
.exe
文件中输入和输出的“快乐路径”场景时,我只使用一个
StandardInput.Write
然后
StandardOutput.ReadToEnd
就可以了。您的代码将如何与多行
控制台.Writelines关联?我不确定是否理解您的问题。。。如果你想写更多的行,重复这个顺序,或者一次写完所有行,然后刷新。它甚至可能会自动刷新,但我不会打赌,但你当然可以尝试。我用预期场景编辑了我的问题。我可以在一个
StandardInput
中从
.exe
文件执行三重
Console.ReadLine
吗?@michasaaucer:仍然不确定问题出在哪里。你想知道如何连接字符串吗?然后查看我的编辑。
this.Process.StandardInput.Write(  "a" + this.Process.StandardInput.NewLine
                                 + "b" + this.Process.StandardInput.NewLine);