[英]How to simulate "enter key press" in Process working in background?
在我的可執行Process
實例中,我有幾個Console.ReadLine
行。 如何在Process.InputStream
類中傳遞Enter key press
(模擬用戶Enter key press
)? 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();
}
我想在我的Process.StandardInput.Write
模擬input string
上的input string
鍵
您可以使用WriteLine()
。
this.Process.StandardInput.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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.