Re: Java Question

  • From: "Stefan Knecht" <knecht.stefan@xxxxxxxxx>
  • To: rgoulet@xxxxxxxxxx
  • Date: Thu, 19 Oct 2006 19:26:20 +0200

Well,

"your" java code only returns the return code of the os command execution.
If you want to return something else (like the output of the command) -
you'll have to adjust your java code to do this. You're only seeing the
output in the console because dbms_java.set_output has been called.
Otherwise you'd find the output in a tracefile in user_dump_dest.

PL/SQL can only "see" what the java code returns, it can't see what's
printed to STDOUT or STDERR on unix.

Stefan

On 10/19/06, Richard J. Goulet <rgoulet@xxxxxxxxxx> wrote:

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 |F*ax: * 508.229.2019 | Cell:508.742.5795

RGoulet@xxxxxxxxxx
: POWERING TRANSFORMATION


GIF image

Other related posts: