1
需要運行和外部命令,輸出寫入任何幫助apreciated一個日誌文件,並捕獲退出狀態的Perl - 捕獲退出狀態和捕獲記錄最好的辦法對外部命令
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";
。
您可能想看看IPC :: Run或IPC :: Open3 – kjprice 2013-03-27 21:29:32
任何原因,特別是您爲什麼不想使用DBI和DBD :: DB2? – 2013-03-29 14:42:08