简体   繁体   English

Perl 捕获子进程的 STDERR 和 STDOUT

[英]Perl catching STDERR and STDOUT of subprocess

I have Perl script which is executing another script.我有正在执行另一个脚本的 Perl 脚本。 How can I ensure that, when CONNECTION.pl is executed, I will capture STDERR and STDOUT, so that I can put it in the log in the parent script?如何确保在执行CONNECTION.pl时,我将捕获 STDERR 和 STDOUT,以便将其放入父脚本的日志中? Bellow is the code from the parent script:波纹管是来自父脚本的代码:

my $systemcmd ='perl bin/CONNECTION.pl "'.$expanded_sql.'" "'.$tmp_file.'" "'.$fetch.'"';

eval {
  my $rc = system($systemcmd );
};

if ($@) {
  $errmsg = $@;
  croak {message=>$errmsg};
  unlink $tmp_file;
} 

Try using Capture::Tiny to wrap the call to system .尝试使用Capture::Tiny包装对system的调用。

Moreover, it might be cleaner to change the Perl script CONNECTION.pl into a module and use it from your script rather than shelling out to call perl again.此外,将 Perl 脚本 CONNECTION.pl 更改为模块并从脚本中使用它可能会更清晰,而不是再次调用 perl。

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

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