How to invoke console application in Perl ?(Reship)
2005-07-17 00:27
405 查看
How to invoke console application in Perl ? |
Perl 是一种很好的脚本语言,与shell相比,能够跨平台是它的优势 之一.本文介绍了怎样用perl调用Oracle的sql loader完成外部数 据导入并且解析sql loader输出的日志. 首先,我们写一个run_load过程来调用sql loader,需要通过管道 的方式来实现. sub run_load { my($sqlldr_parfile,$sqlldr_log) = @_; $sqlldr_exe = "$ENV/bin/sqlldr"; $command = "|$sqlldr_exe parfile=$sqlldr_parfile log=$sqlldr_log"; write_log_file("Command:$command",$logdir); open(LDR_FH, $command)|| die "Couldn't execute $sqlldr_exen"; print LDR_FH "exitn"; close LDR_FH; } parfile:sql loader用到的参数文件 log: sql loader输出的日志文件 然后,我们需要写一个parseErrors的过程来解析sql loader 输出的 日志文件. 这里面用到了正则表达式. 事实上,perl是对正则表达式 支持最好的脚本语言. sub parseErrors() { my ($ldr_log)=@_; if (-e $_[0]) { open(LOGFILE, $_[0]) || die "Can't open SQL LOADER's log file:$!n"; @arr_log = ; close LOGFILE; $cont = "@arr_log"; print STDOUT $cont; if(($cont !~ /ORA-[0-9]/) && ($cont !~ /SQL*Loader-[0-9]/)) { write_log_file("SQL LOADER: No Errors",$logdir); return 1; } elsif($cont =~ /SQL*Loader-[0-9]/) { write_log_file("SQL LOADER: Detected error from $ldr_log",$logdir); return 0; } } else { write_log_file("SQL LOADER's log file doesn't exist: $_[0]",$logdir); return 0; } } 分析: 1. 如果sql loader 运行时出现错误,日志文件中必然会有ORA-XXXXX 或者 SQL*Loader-XXXXX这样的特征字符,我们就用它来作为解析的标准. 2. write_log_file 是一个通用的过程,完成写日志文件的功能.你应该 很容易就能写出来的. 最后,我们可以写一个main()的过程,来调用上面的两个子过程. |
相关文章推荐
- How to load "CodedUItestmethod" in another "consoleapplication".
- How to debug c++ console application with argument in visual studio 2012
- How to write a console application running in background (hidden window)?
- How to discover memory usage of my application in Android
- Java EE 6: How to implement “Stay Logged In” when user login in to the web application
- How To Customise the Tab Bar (UITabBar) in an iPhone Application (Part 1 of 2)
- How to invoke Java web service in ASP.net using C#
- How do I lock the orientation to portrait mode in a iPhone Web Application?
- [转载]How to hide the OK button in the dialog in .Net Compact Framework application?
- How to get the IIS root path in other application.
- How to add a Custom Pull to Refresh in your iOS Application
- How To Customise the Tab Bar (UITabBar) in an iPhone Application (Part 2 of 2)
- How to use sharepoint webservices in web application
- How to open another page in HTML5 Builder Server Mobile Application
- How to declare global variables in Android? --- Application Subclasses
- 【转】How to view word document in WPF application
- How to publish an App-V-enabled application in Citrix XenApp
- How to Integrate Excel in a Windows Form Application using the WebBrowser
- How to register a keyboard shortcut (hot key) in a .NET Windows Forms Application
- How To Create A Client Server Application In Minutes[如何在几分钟的时间里编写一个客户机/服务器控制台程序]