简体   繁体   English

在Unix上分离命令行输出(来自用户交互的处理)的方法是什么?

[英]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读取,因为系统通常会在stdindup()将其打开到stdoutstderr打开一次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.

相关问题 当将其用于进一步处理时,命令行输出的一种良好格式是什么? - What is a good format for command line output when it is being used for further processing? 处理C ++中的代码的命令行参数以进行随机输入和用户输入 - Processing command line arguments for a code in c++ for random and user input 命令设计模式和用户交互 - Command design pattern and user interaction 处理命令行参数 - Processing command line argument 如何从UNIX中的命令行编译简单的Boost程序 - How to compile a simple boost program from command line in unix 有什么方法可以在命令行中获取可读的 gcc 错误和警告 output? - Is there any way to get readable gcc error and warning output at the command line? 将命令行分隔为单独的const char * - Separate command line into separate const char * 优化器和专用于 what 命令的字符串之间的交互 - Interaction between the optimizer and strings dedicated to the what command 逐行处理文件并解析该行以获取单独的变量 - Processing a file line by line and parsing the line to get separate variables 使用 QProcess 执行 CMD 命令以将 output 作为 QString 的正确方法是什么? - What is the correct way to execute a CMD command with QProcess to get the output as QString?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM