简体   繁体   English

C#如何在执行控制台应用程序期间禁用linux终端用户输入

[英]C# How to disable linux terminal user input during the execution of a Console Application

When I run my console application in windows, unless I'm actively reading input (ie via Console.Read...) nothing happens when I type in the console. 当我在Windows中运行控制台应用程序时,除非我正在主动读取输入(即通过Console.Read ...),否则在键入控制台时都不会发生任何事情。

When I'm running the same console application in linux, whatever I type is inserted in the middle of what the application is writing to the console at the time. 当我在linux中运行相同的控制台应用程序时,我键入的任何内容都会插入到应用程序当时写入控制台的中间位置。

Is there any way to prevent/capture/flush the user input in the terminal during the execution of the program? 在执行程序期间,是否有任何方法可以防止/捕获/清除终端中的用户输入?

You can disable echo on the shell before running your program and re-enable it afterwards: 您可以在运行程序之前在外壳上禁用回显,然后再重新启用它:

$ stty_bak=`stty -g`
$ stty -echo
$ <run your command / program>
$ stty $stty_bak

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM