Java Question

  • From: "Richard J. Goulet" <rgoulet@xxxxxxxxxx>
  • To: <oracle-l@xxxxxxxxxxxxx>
  • Date: Thu, 19 Oct 2006 10:30:38 -0400

    First off, I'm pretty novice at Java so this could be a bit
rudimentary but please bear with me.  I've found and adapted the Java
procedure on Ask Tom to run OS commands on Unix.  Works rather well from
Sql*Plus, but I want to bury calls to the procedure into some procedural
code that needs to make decisions based on the output.  The code I've
got looks like:
 
create or replace and compile
java source named "Util" as
import java.io.*;
import java.lang.*;
public class Util extends Object
{
   public static int RunThis(String args)
   { Runtime rt = Runtime.getRuntime();
     int rc = 0;
     try
     { Process p = rt.exec(args);
       int bufSize = 4096;
       BufferedInputStream bis = new
BufferedInputStream(p.getInputStream(), bufSize);
       int len;
       byte buffer[] = new byte[bufSize];
       // Echo back what the program spit out
       while ((len = bis.read(buffer, 0, bufSize)) != -1)
       System.out.write(buffer, 0, len);
       rc = p.waitFor();
     }
     catch (Exception e)
     { e.printStackTrace();
       rc = -1; 
     } 
     finally
     { return rc;
     }
    }
}
/

In Sql*plus I get this displayed on the screen:
 
Filesystem            kbytes    used   avail capacity  Mounted on
/dev/md/dsk/d2       12397228 3936915 8336341    33%    /
 
Now the procedure does return a 0, meaning that the Java executed
normally and I am passing a 'df -k <mount_point>' to the prodecure
(Solaris9).  What I'd like the procedure to return is the available disk
space remaining or 8336341.  Anybody got any ideas??
 

  
Dick Goulet, Senior Oracle DBA

45 Bartlett St  Marlborough, Ma 01752, USA
Tel.: 508.573.1978 |Fax:  508.229.2019 | Cell:508.742.5795 

RGoulet@xxxxxxxxxx
: POWERING TRANSFORMATION 

 

GIF image

Other related posts: