Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > Oracle
| Search | Today's Posts | Mark Forums Read
Oracle General Oracle database discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Oracle section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 12th, 2003, 06:24 AM
Authorized User
 
Join Date: Aug 2003
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to call an external program?

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
 
Old November 13th, 2003, 07:13 AM
Registered User
 
Join Date: Nov 2003
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hello schockp!

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

please consult

http://asktom.oracle.com/pls/ask/f?p...A: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


 
Old November 13th, 2003, 07:41 AM
Authorized User
 
Join Date: Aug 2003
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you Oli! As soon as I have some time I'll take a look at it.

Pieter





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to call an External program to run ? itayzoro VB.NET 2002/2003 Basics 0 July 31st, 2008 01:45 AM
call external program from vb.net praswani Pro VB.NET 2002/2003 2 October 18th, 2007 07:19 AM
i can not run external program. pumpui VS.NET 2002/2003 0 December 5th, 2004 02:08 PM
How to call java external files? hlchuah77 Java GUI 2 September 12th, 2004 02:10 PM
Executing an external program. saint VB.NET 2002/2003 Basics 3 July 22nd, 2003 08:30 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.