如何在Perl中同时捕获stderr,stdout和退出代码? [英] How do you capture stderr, stdout, and the exit code all at once, in Perl?
问题描述
是否可以从Perl运行外部进程,捕获其stderr,stdout以及进程退出代码?
Is it possible to run an external process from Perl, capture its stderr, stdout AND the process exit code?
我似乎能够做到这些的组合,例如使用反引号获取标准输出,使用IPC :: Open3捕获输出,使用system()获取退出代码.
I seem to be able to do combinations of these, e.g. use backticks to get stdout, IPC::Open3 to capture outputs, and system() to get exit codes.
如何一次捕获stderr,stdout和退出代码?
How do you capture stderr, stdout, and the exit code all at once?
推荐答案
如果您重新阅读了IPC :: Open3的文档,则会看到一条注释,应调用 $?
.
If you reread the documentation for IPC::Open3, you'll see a note that you should call waitpid to reap the child process. Once you do this, the status should be available in $?
. The exit value is $? >> 8
. See
$?
in perldoc perlvar.
这篇关于如何在Perl中同时捕获stderr,stdout和退出代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!