IPC :: Open3遇到问题 [英] Trouble with IPC::Open3

查看:223
本文介绍了IPC :: Open3遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用IPC :: Open3编写一个简单的脚本.该脚本不会向stdout或stderr产生任何输出,而我希望两者都输出.

I am writing a simple script using IPC::Open3. The script produces no output to either stdout or stderr, while I would expect output to both.

完整的源代码:

#!/usr/bin/env perl 

use strict;
use warnings;
use utf8;

use IPC::Open3;

pipe my $input, my $output or die $!;
my $pid =  open3(\*STDIN, $output, \*STDERR, 'dd', 'if=/usr/include/unistd.h') or die $!;

while(<$input>) {
    print $_."\n";
}
waitpid $pid, 0;

我可以肯定我使用的IPC :: Open3错误.但是,我仍然对应该做的事情感到困惑.

I am fairly certain that I am using IPC::Open3 incorrectly. However, I am still confused as to what I should be doing.

推荐答案

它是pipe.不知道为什么会在那里,我不能说更多.效果很好.

It's the pipe. Without knowing why it's there I can't say more. This works fine.

my $reader;
my $pid =  open3(\*STDIN, $reader, \*STDERR, 'dd', 'if=/usr/include/unistd.h') or die $!;

while(<$reader>) {
    print $_."\n";
}
waitpid $pid, 0;

我意识到这可能只是一个例子,但万一不是……这完全是您正在做的事.您可以使用反引号来实现.

I realize it's probably just an example, but in case it's not... this is complete overkill for what you're doing. You can accomplish that with backticks.

print `dd if=/usr/include/unistd.h`


IPC :: Open3有点复杂.还有更好的模块,例如 IPC :: Run

这篇关于IPC :: Open3遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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