tee 命令是否总是等待 EOF?

发布于 2024-07-05 07:07:01 字数 466 浏览 9 评论 0原文

我想将命令的输出记录到 stdout 以及日志文件中。 我已经安装了 Cygwin,并且正在尝试使用 tee 命令来完成此操作。

devenv mysolution.sln /build myproject "Release|Win32" | tee build.log

问题在于,tee 似乎坚持在将任何内容输出到 stdout 或日志文件之前等待文件末尾。 这消除了所有的要点,即有一个日志文件供将来参考,但也有一些 stdout 日志记录,以便我可以轻松地查看构建进度。

tee 的选项似乎仅限于 --append--ignore-interrupts--help--版本。 那么还有另一种方法可以实现我想要做的事情吗?

I'd like to log the output of a command to stdout as well as to a log file. I've got Cygwin installed and I'm trying to use the tee command to accomplish this.

devenv mysolution.sln /build myproject "Release|Win32" | tee build.log

Trouble is that tee seems to insist on waiting for the end of file before outputting anything to either stdout or the log file. This takes away the point of it all, which is to have a log file for future reference, but also some stdout logging so I can easily see the build progress.

tee's options appear to be limited to --append, --ignore-interrupts, --help, and --version. So is there another method to get to what I'm trying to do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ゝ偶尔ゞ 2024-07-12 07:07:01

tee似乎坚持等待
输出任何内容之前的文件结尾
到标准输出或日志文件。

这绝对不应该发生——它会让 T 恤几乎毫无用处。 这是我编写的一个简单测试,用于对此进行测试,并且它绝对不会等待 eof。

$ cat test
#!/bin/sh
echo "hello"
sleep 5
echo "goodbye"

$ ./test | tee test.log
hello
<pause>
goodbye

tee seems to insist on waiting for the
end of file before outputting anything
to either stdout or the log file.

This should definitely not be happening - it would render tee nearly useless. Here's a simple test that I wrote that puts this to the test, and it's definitely not waiting for eof.

$ cat test
#!/bin/sh
echo "hello"
sleep 5
echo "goodbye"

$ ./test | tee test.log
hello
<pause>
goodbye
再见回来 2024-07-12 07:07:01

您可以输出到文件并 tail -f 文件。

devenv mysolution.sln /build myproject "Release|Win32" > 构建.log &

tail -f 构建.log

You can output to the file and tail -f the file.

devenv mysolution.sln /build myproject "Release|Win32" > build.log &

tail -f build.log

萌梦深 2024-07-12 07:07:01

自己写吧! (这里的重点是自动刷新 ($|) 设置已打开,因此看到的每一行都会立即刷新。这可能是真正的 tee 命令所缺少的.)

#!/usr/bin/perl -w
use strict;
use IO::File;
$| = 1;
my @fhs = map IO::File->new(">$_"), @ARGV;
while (my $line = <STDIN>) {
    print $line;
    $_->print($line) for @fhs;
}
$_->close for @fhs;

您可以将脚本命名为您想要的任何名称。 我称之为perlmilktee! :-P

Write your own! (The point here is that the autoflush ($|) setting is turned on, so every line seen is flushed straight away. This may perhaps be what the real tee command lacked.)

#!/usr/bin/perl -w
use strict;
use IO::File;
$| = 1;
my @fhs = map IO::File->new(">$_"), @ARGV;
while (my $line = <STDIN>) {
    print $line;
    $_->print($line) for @fhs;
}
$_->close for @fhs;

You can call the script anything you want. I call it perlmilktee! :-P

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文