简体   繁体   中英

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).

How can I achieve this, if I can't just send all interaction with the user to cerr (not everything is an error)?

/dev/tty是通常的方式,但是在大多数类似Unix的操作系统上,也可以从cerr / stderr读取,因为系统通常会在stdindup()将其打开到stdoutstderr打开一次tty。

当您的stdout通过管道传输到其他位置时,在终端上显示某些内容的唯一方法(除了诸如curses和dialog之类的东西)是stderr。

If you need user interaction, open /dev/tty, it will be the controlling terminal for the process. Standard error and standard input may be redirected as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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