By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,848 Members | 1,290 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,848 IT Pros & Developers. It's quick & easy.

error handling...

P: 58
Hey friends
i just wrote some code that finds a zip file in a folder, unzips it using system() call to winzip32.exe.
the contents of zip is an oracle dmp file. I next use another system() call to oracles imp command to import the dmp file to a schema in oracle. It works just fine. What I need to do now is copy the contents of the shell window output to a text file so that i can look later to see if it worked correctly..

Expand|Select|Wrap|Line Numbers
  1. use warnings;
  2. use strict;
  5. my $InDir="D:\\temp";
  6. my @TempDir;  
  7.   opendir(DIR, $InDir) or die "Unable to open dir $InDir: $!\n";
  8.   @TempDir = reverse sort readdir(DIR);
  9.   my $tmp_dir = $TempDir[2];
  10.   close(DIR);
  11.   #$tmp_dir is now the most recent archive 
  13. my $winzip="C:\\Progra~1\\WinZip\\winzip32\.exe -min -e -o $InDir\\$tmp_dir $InDir";
  15. func1();
  17. my @TempDir2;  
  18.   opendir(DIR, $InDir) or die "Unable to open dir $InDir: $!\n";
  19.   @TempDir2 = reverse sort readdir(DIR);
  20.   my $tmp_dir2 = $TempDir[3];
  21.   close(DIR);
  22.   #$tmp_dir2 is now the most recent unzipped archive
  24. my $oracle="imp user/password\@instance FROMUSER=fuser TOUSER=tuser FILE=$InDir\\$tmp_dir2 TABLES=($tmp_dir2) FEEDBACK=1000000 LOG=$InDir\\logs\\$tmp_dir2\.log";
  27. func2();
  29. sub func1{
  30.   system "$winzip";
  31. }
  33. sub func2{
  34.   system "$oracle";
  35. }
when i run in a cmd window here are the messages i get as the perl script runs


C:\Progra~1\WinZip\winzip32.exe -min -e -o D:\temp\ D:\temp

imp user/password@instance FROMUSER=fuser TOUSER=tuser FILE=D:\temp\TMP2.dmp TABLES=(TMP2) FEEDBACK=1000000

Import: Release - Production on Thu Apr 24 15:14:17 2008

Copyright (c) 1982, 2005, Oracle. All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release - 64bit
With the Partitioning, OLAP and Data Mining options

Export file created by EXPORT:V10.02.01 via conventional path
import done in WE8MSWIN1252 character set and AL16UTF16 NCHAR character set
import server uses AL32UTF8 character set (possible charset conversion)
. importing USER's objects into USER
. . importing table "TMP2"
477438 rows imported
Import terminated successfully without warnings.

so is it possible to have that all exported out to a text file?
Thanks ahead of time
Apr 24 '08 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 410
You can just redirect the output to a file on command line. You can do this either using system command or using reverse quotes.

Using system() command:
Expand|Select|Wrap|Line Numbers
  1. sub func1{
  2.   system("$winzip >D:\output.txt");
  3. }
  5. sub func2{
  6.   system("$oracle >>D:\output.txt");
  7. }
Using reverse quotes:
Expand|Select|Wrap|Line Numbers
  1. open(OUT,">D:\\output.txt");
  2. @out1=`$winzip`;
  3. @out2=`$oracle`;
  4. print OUT @out1;
  5. print OUT @out2;
  6. close(OUT);
Apr 25 '08 #2

P: 2
Please check the below url for
export & import tables in 10g using shell script
Nov 23 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.