[英]What is the way to separate command line output (processing from user interaction) on Unix?
I'm writing a console application in which user interaction might be necessary (prompt for keyboard input, cli arguments etc.), but I want to keep it separate from the result of the processing (which goes to cout, in a way that it can be piped to some other application). 我正在编写一个控制台应用程序,在该应用程序中可能需要用户交互(提示输入键盘,cli参数等),但是我想将其与处理结果(以cout的方式进行处理)分开可以通过管道传输到其他应用程序)。
How can I achieve this, if I can't just send all interaction with the user to cerr (not everything is an error)? 如果我不能仅将与用户的所有互动发送给cerr(不是所有都是错误的),该如何实现?
/dev/tty
是通常的方式,但是在大多数类似Unix的操作系统上,也可以从cerr
/ stderr
读取,因为系统通常会在stdin
和dup()
将其打开到stdout
和stderr
打开一次tty。
当您的stdout通过管道传输到其他位置时,在终端上显示某些内容的唯一方法(除了诸如curses和dialog之类的东西)是stderr。
If you need user interaction, open /dev/tty, it will be the controlling terminal for the process. 如果需要用户交互,请打开/ dev / tty,它将成为该过程的控制终端。 Standard error and standard input may be redirected as well. 标准错误和标准输入也可以重定向。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.