简体   繁体   English

如何在perl脚本中捕获gzip错误消息

[英]how to capture gzip error message in perl script

I am getting zipping error when I try to open the zip file. 尝试打开zip文件时出现压缩错误。 I want to capture that error msg. 我想捕获该错误消息。 Plz help me in doing that. 请帮助我做到这一点。 I need the solution in perl. 我需要perl中的解决方案。

eg:: 例如::

gzcat zipfile.gz gzcat zipfile.gz

gzip: zipfile.gz: unexpected end of file gzip:zipfile.gz:文件意外结束

I want to capture "unexpected end of file" into a variable. 我想将“意外的文件结尾”捕获到一个变量中。

How can I do that in PERL ?? 我如何在PERL中做到这一点?

Thanks in advance. 提前致谢。

I think this module can help: 我认为该模块可以帮助您:

http://metacpan.org/pod/IO::CaptureOutput http://metacpan.org/pod/IO::CaptureOutput

You need to redirect your stderr output . 您需要重定向stderr输出。 One way to do this (might depend on your shell though), is - 一种方法(尽管可能取决于您的外壳)是-

my $res = `mycommand 2>&1`;
print "output + errors: $res\n"

There are also other suggestions here - How do you capture stderr, stdout, and the exit code all at once, in Perl? 这里还有其他建议- 如何在Perl中同时捕获stderr,stdout和退出代码?

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

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