error handling...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • erbrose
    New Member
    • Oct 2006
    • 58

    error handling...

    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..

    Code:
    use warnings;
    use strict;
    
    
    my $InDir="D:\\temp";
    my @TempDir;  
      opendir(DIR, $InDir) or die "Unable to open dir $InDir: $!\n";
      @TempDir = reverse sort readdir(DIR);
      my $tmp_dir = $TempDir[2];
      close(DIR);
      #$tmp_dir is now the most recent t.com archive 
    
    my $winzip="C:\\Progra~1\\WinZip\\winzip32\.exe -min -e -o $InDir\\$tmp_dir $InDir";
    
    func1();
    
    my @TempDir2;  
      opendir(DIR, $InDir) or die "Unable to open dir $InDir: $!\n";
      @TempDir2 = reverse sort readdir(DIR);
      my $tmp_dir2 = $TempDir[3];
      close(DIR);
      #$tmp_dir2 is now the most recent unzipped t.com archive
    
    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";
    
    
    func2();
    
    sub func1{
      system "$winzip";
    }
    
    sub func2{
      system "$oracle";
    }
    when i run in a cmd window here are the messages i get as the perl script runs

    D:\data\scripts >test.pl

    D:\data\scripts >
    C:\Progra~1\Win Zip\winzip32.ex e -min -e -o D:\temp\TMP2.zi p D:\temp

    D:\data\scripts >
    imp user/password@instan ce FROMUSER=fuser TOUSER=tuser FILE=D:\temp\TM P2.dmp TABLES=(TMP2) FEEDBACK=100000 0
    LOG=D:\temp\TMP 2.dmp.log

    Import: Release 10.2.0.1.0 - 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 10.2.0.3.0 - 64bit
    Production
    With the Partitioning, OLAP and Data Mining options

    Export file created by EXPORT:V10.02.0 1 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
  • nithinpes
    Recognized Expert Contributor
    • Dec 2007
    • 410

    #2
    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:
    Code:
    sub func1{
      system("$winzip >D:\output.txt");
    }
    
    sub func2{
      system("$oracle >>D:\output.txt");
    }
    Using reverse quotes:
    Code:
    open(OUT,">D:\\output.txt");
    @out1=`$winzip`;
    @out2=`$oracle`;
    print OUT @out1;
    print OUT @out2;
    close(OUT);
    Last edited by nithinpes; Apr 25 '08, 05:27 AM. Reason: removed original quote

    Comment

    • Mohanj
      New Member
      • Feb 2007
      • 2

      #3
      Please check the below url for
      export & import tables in 10g using shell script

      #!/usr/bin/bash Export Table:- export ORACLE_SID=SNM export ORACLE_HOME=/opt/app/oracle/product/10.2.0 #su – oracle -c /opt/app/oracle/p...

      Comment

      Working...