[英]How does IPC::Open3 enable autoflush for CHLD_IN
The documentation for IPC::Open3 states: IPC :: Open3的文档指出:
The CHLD_IN will have autoflush turned on
But nothing in the source code mentions IO::Handle::autoflush
. 但是源代码中没有任何内容提到
IO::Handle::autoflush
。 What mechanism does the module use to turn on autoflush for CHLD_IN
? 模块使用什么机制为
CHLD_IN
打开自动CHLD_IN
?
Buffering is disabled with the following line 使用以下行禁用缓冲
select((select($handles[0]{parent}), $| = 1)[0]); # unbuffer pipe
which could be rewritten as 可以改写成
my $old_fh = select($handles[0]{parent});
$| = 1;
select($old_fh);
The traditional way to disable output buffering in Perl is via the $|
在Perl中禁用输出缓冲的传统方法是通过
$|
variable. 变量。 From
man perlvar
: 来自
man perlvar
:
- HANDLE->autoflush( EXPR )
处理->自动冲洗(EXPR)
- $OUTPUT_AUTOFLUSH
$ OUTPUT_AUTOFLUSH
- $|
$ |
If set to nonzero, forces a flush right away and after every write or print on the currently selected output channel.
如果设置为非零,则在当前选择的输出通道上每次写入或打印后立即强制刷新。 Default is 0 (regardless of whether the channel is really buffered by the system or not; $| tells you only whether you've asked Perl explicitly to flush after each write).
缺省值为0(无论通道是否真正被系统缓冲; $ |仅告诉您是否在每次写操作后都明确要求Perl刷新)。 STDOUT will typically be line buffered if output is to the terminal and block buffered otherwise.
如果输出到终端,则STDOUT通常将被行缓冲,否则将被块缓冲。 Setting this variable is useful primarily when you are outputting to a pipe or socket, such as when you are running a Perl program under rsh and want to see the output as it's happening.
设置此变量主要在输出到管道或套接字时很有用,例如在rsh下运行Perl程序并希望看到正在发生的输出时。 This has no effect on input buffering.
这对输入缓冲没有影响。 See getc for that.
参见getc。 See select on how to select the output channel.
请参阅选择如何选择输出通道。 See also IO::Handle.
另请参见IO :: Handle。
Mnemonic: when you want your pipes to be piping hot.
助记符:当您希望管道变热时。
Setting $|
设置
$|
acts on "the currently selected output channel" which is set with the one-argument form of select
. 对“当前选定的输出通道”起作用,该通道以
select
的一个参数形式设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.