create or replace and compile java source named util as
import java.io.*;
import java.util.*;
public class util
{
//
// Executes an operating system command. The command shall be fully qualified.
// The Java connects with silent login. No environment set-up files are run
// and no path is set. The mode can be "sync" or "async" for respectively
// synchronous and asynchronous execution
//
// Requires at least some of the following permissions:
// call dbms_java.grant_permission( '<user>', 'SYS:java.io.FilePermission', '<<ALL FILES>>', 'execute' );
// call dbms_java.grant_permission( '<user>', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '' );
// call dbms_java.grant_permission( '<user>', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '' );
//
static public int OSCmd(String cmd, String mode, String[] output)
throws IOException, InterruptedException
{
System.out.println("OSCmd "+cmd+" ("+mode+")");
output[0]="";
// start command
Process proc = Runtime.getRuntime().exec(cmd);
if (mode.equals("sync"))
{
// get commands stdout and stderr
InputStream stdout = proc.getInputStream();
InputStream stderr = proc.getErrorStream();
String str;
// Stdout
BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
while ((str = br.readLine()) != null)
output[0]+=str+"\n";
br.close();
// Stderr
br = new BufferedReader(new InputStreamReader(stderr));
while ((str = br.readLine()) != null)
output[0]+=str+"\n";
br.close();
// wait for command to terminate
proc.waitFor();
return proc.exitValue();
}
return 0;
}
}
;