Subject: how to call an external program?
Posted By: schockp Post Date: 11/12/2003 5:24:45 AM
I was wondering if it's possible to call an external program? Each time there's a modification in a table, I want to call another program with the modifications made.

Is there any good tutorial about this? Are there any restrictions on calling an external program?

Pieter
Reply By: stratmo Reply Date: 11/13/2003 6:13:10 AM
hello schockp!

it's popssible. please think of the security drwbacks involved doing this.

please consult

http://asktom.oracle.com/pls/ask/f?p=4950:8:6057230915856871718::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:952229840241,

there is a brief explanation for solving your problem. (sadly it's unix-only (no offence meant here!))

i found an example in my personal archive which also is able to do MS-Windows-calls. I got it out of the internet, but i couldn't find it once more.

/*=========================================*/

/*      ProcessRunner.java
*       @author: Charles Bell
*       @version: June 21, 2001*/
import java.io.*;
/**     Executes the String arguments, displays the commands being executed, and displays
*       any results.
*/
public class ProcessRunner {
    /** Instantiates a class and runs the commands passed in the aguments.       
    */
    public static void main(String[] args) {
        ProcessRunner runner = new ProcessRunner();
        String[] command = args;
        //{ "exp oli/admin@dbtitan file = olitest.dmp log = olitest.log" };
        runner.runCommand(command);
    }
    /**     Runs the commands in a process and displays the results.    
    */
    public void runCommand(String[] args) {
        int number = args.length;
        try {
            String[] commands;
            if (System.getProperty("os.name").compareToIgnoreCase("windows")
                > 0) {
                commands = new String[number + 2];
                commands[0] = "command.com";
                //for Windows 95, 98, ME. etc.                
                if (System.getProperty("os.name").compareToIgnoreCase("nt")
                    > 0) {
                    commands[0] = "cmd.exe"; //for Windows NT
                }
                commands[1] = "/c";
                for (int i = 0; i < number; i++) {
                    commands[i + 2] = args[i];
                }
            } else {
                commands = new String[number];
                for (int i = 0; i < number; i++) {
                    commands[i] = args[i];
                }
            }
            System.out.print("Executing: ");
            for (int i = 0; i < commands.length; i++) {
                System.out.print(commands[i] + " ");
            }
            Runtime runtime = Runtime.getRuntime();
            Process process = runtime.exec(commands);
            // Because some native platforms only provide limited buffer size             
            // for standard input and output streams, failure to promptly write             
            // the input stream or read the output stream of the subprocess             
            // may cause the subprocess to block, and even deadlock.            
            CheckStream csin = new CheckStream(process.getInputStream());
            CheckStream cserr = new CheckStream(process.getErrorStream());
            csin.start();
            cserr.start();
            System.out.print("Waiting for command process to terminate.");
            int done = process.waitFor();
            process.destroy();
            System.out.println("... Done.");
        } catch (InterruptedException ie) {
            System.out.println("InterruptedException: " + ie.getMessage());
        } catch (IOException ioe) {
            System.out.println("IOException: " + ioe.getMessage());
        }
    } /**     Inner class for checking the results if any of an InputStream.      */
    class CheckStream extends Thread {
        BufferedReader br;
        String lineread = "";
        /**     Constructor needs an InputStream to form an anonymous              
        *       InputStreamReader which is used to create a BufferedReader             
        *       for reading the stream.              
        */
        CheckStream(InputStream is) {
            this.br = new BufferedReader(new InputStreamReader(is));
        }
        /**     Reads the input stream and displays anything returned.             
         **/
        public void run() {
            try {
                while ((lineread = br.readLine()) != null) {
                    System.out.println(lineread);
                }
            } catch (IOException ioe) {
                System.out.println("IOException: " + ioe.getMessage());
            }
        }
    }
}
/*=======================================*/

I hope this helps. wrap this java.method in pl/sql-procedure, grant the privileges needed and it should work.

Bye!
Oli


Reply By: schockp Reply Date: 11/13/2003 6:41:10 AM
Thank you Oli! As soon as I have some time I'll take a look at it.

Pieter


Go to topic 6206

Return to index page 1006
Return to index page 1005
Return to index page 1004
Return to index page 1003
Return to index page 1002
Return to index page 1001
Return to index page 1000
Return to index page 999
Return to index page 998
Return to index page 997