需要运行外部命令,将输出写入日志文件并捕获退出状态
my $cmd = "db2 \"insert into schema.tablea (id, name, city) values (99, 'Micheal', 'London')\" ";
open my $log, ">", "logfile.log";
my $rt = open(OUTPUT,"$cmd 2>&1 | " );
while (<OUTPUT>){
chomp;
print $log $_, "\n";
print $_, "\n";
}
close(OUTPUT);
close($log);
print "Exit status is $rt\n";
任何帮助都将不胜感激。