同时保持在屏幕上如何管标准输出? (而不是一个输出文件) [英] How to pipe stdout while keeping it on screen ? (and not to a output file)

查看:129
本文介绍了同时保持在屏幕上如何管标准输出? (而不是一个输出文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想管程序的标准输出,同时保持它在屏幕上。

I would like to pipe standard output of a program while keeping it on screen.

通过一个简单的例子(回声这里使用的是只是为了说明用途):

With a simple example (echo use here is just for illustration purpose) :

$回声'EE'|富结果
EE < - 输出我想看看

$ echo 'ee' | foo
ee <- the output I would like to see

我知道三通可以复制标准输出到文件,但是这不是我想要的。结果
$回声'EE'|三通output.txt的|富

I know tee could copy stdout to file but that's not what I want.
$ echo 'ee' | tee output.txt | foo

我试过结果
$回声'EE'|三通的/ dev /标准输出|富但因为发球输出到的/ dev /标准输出通过管道输送到

I tried
$ echo 'ee' | tee /dev/stdout | foo but it does not work since tee output to /dev/stdout is piped to foo

推荐答案

下面是一个在任何Unix / Linux上执行工作,假设它关心遵循解决方案 POSIX 标准。它适用于一些非Unix的环境中,如的cygwin 了。

Here is a solution that works at on any Unix / Linux implementation, assuming it cares to follow the POSIX standard. It works on some non Unix environments like cygwin too.

echo 'ee' | tee /dev/tty | foo

参考:公开组基本规范问题7
IEEE标准1003.1,2013版,§10.1

为/ dev / tty的

与工艺组过程中,如果任何关联。 这是
  对于那些希望以确保程序或shell程序有用
  消息写入
或从读终端数据无论怎样
  输出已经重定向。
它也可以用于应用程序
  输入输出期望当要求输出,一个文件的名称和
  这是烦人找出终端目前正在使用的东西。在每个过程中,对于控制终端的代名词

Associated with the process group of that process, if any. It is useful for programs or shell procedures that wish to be sure of writing messages to or reading data from the terminal no matter how output has been redirected. It can also be used for applications that demand the name of a file for output, when typed output is desired and it is tiresome to find out what terminal is currently in use. In each process, a synonym for the controlling terminal

这篇关于同时保持在屏幕上如何管标准输出? (而不是一个输出文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆