简体   繁体   English

linux stdout管道问题

[英]linux stdout pipe issues

I have a server program just writes output log to STDOUT. 我有一个服务器程序只是将输出日志写入STDOUT。 I also have another Perl shell script named "logfile" ,it will gets data from STDIN and shows some output. 我还有另一个名为“logfile”的Perl shell脚本,它将从STDIN获取数据并显示一些输出。

linux$ server |  logfile

at first log-file has output ,but after a few moments it stops.. is there anyone has came across this problem? 在第一个日志文件有输出,但过了一会儿它停止..有没有人遇到过这个问题?

server probably buffers its output, feeding it to the pipe in chunks. server可能会缓冲其输出,将其以块的形式提供给管道。 Is server a Perl script? server是Perl脚本吗? Add

$| = 1;

or 要么

use Handle qw( );
STDOUT->autoflush(1);

to it to disable buffering for STDOUT. 它禁用STDOUT的缓冲。 (Well, the first one will disable buffering for whatever handle you have select ed, but that's STDOUT by default.) (好吧,第一个会为你select任何句柄禁用缓冲,但默认情况下这是STDOUT。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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