在这个时候,使用IPC::Run试图模仿下面的内容并不能产生我想要的效果。不幸的是,我还不太熟悉使用IPC::Run重定向来解决我自己的问题,我需要使用SO的大量知识库。
命令我在模仿
echo | openssl s_client -connect google.com:443 2>/dev/null |openssl x509这将显示使用openssl从远程服务器检索的SSL证书。它正确工作的关键是stderr的stderr泵到/dev/null,因为openssl将使用stderr输出附加信息(不是真正的错误),如果没有这一点,将命令管道传输到openssl x509将失败。
这是IPC::Run进来的地方。我需要在perl中使用openssl的这个功能,使用IPC::Run,因为这是我目前正在使用的所有其他函数。不幸的是,以我执行shell重定向的方式使用IPC::Run --比如2>/dev/null --不会引起shell的工作,运行命令并添加2>/dev/null只会将其作为参数附加到openssl调用中。
目前,我有以下内容,这将在没有烦人的stderr问题的情况下工作。而且,openssl命令也没有一致的方法来抑制它。
use IPC::Run qw( run );
my ( $out, $err );
my @cmd = qw(echo);
my @cmd2 = qw(openssl s_client -connect google.com:443:443);
my @cmd3 = qw(openssl x509);
run \@cmd, "|", \@cmd2, "|", \@cmd3, \$out, \$err;
if ( $err ne '' ) {
print $err;
}
else {
print "$out\n";
}所以基本上,我需要放弃@cmd2 2的stderr,这通常是用
run \@cmd, \$in, \$out, \undef;但是,由于在@cmd2 3中以stdin的形式存在,所以不能将stderr从@cmd2 2重定向,因为stderr的描述符是stdout的描述符。我认为必须有一种方法来抑制在两个管道之间使用这个模块的'stderr‘,但是我还没有弄清楚它,而且我对I/O操作还不太熟悉,不能很快得到它。有人从经验中得到这样做的建议吗?
发布于 2014-01-15 22:16:51
“回声”不需要。如果您只想关闭s_client打开的连接,请使用已关闭的stdin。同样,在您的示例中,您连接到google.com:443:443,这是可选的:443太多了。下面这些对我来说很有用
use IPC::Run 'run';
my @cmd1 = qw(openssl s_client -connect google.com:443);
my @cmd2 = qw(openssl x509);
my $stdout = my $stderr = '';
run \@cmd1, '<', \undef, '|', \@cmd2, '2>', \$stderr, '>', \$stdout;
print $stdout;https://stackoverflow.com/questions/21129154
复制相似问题