Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2006
    Posts
    2

    Unanswered: shell commands from pl/sql on windows using oracle 8.1.7+

    hi,

    i'm trying to execute a batch and cannot get it to work...

    i did not have java install initially so i install the jvm..

    CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Host" AS
    import java.io.*;
    public class Host {
    public static void executeCommand(String command) {
    try {
    String[] finalCommand;
    if (isWindows()) {
    finalCommand = new String[4];
    // Use the appropriate path for your windows version.
    finalCommand[0] = "C:\\windows\\system32\\cmd.exe"; // Windows XP/2003
    //finalCommand[0] = "C:\\winnt\\system32\\cmd.exe"; // Windows NT/2000
    finalCommand[1] = "/y";
    finalCommand[2] = "/c";
    finalCommand[3] = command;
    }
    else {
    finalCommand = new String[3];
    finalCommand[0] = "/bin/sh";
    finalCommand[1] = "-c";
    finalCommand[2] = command;
    }

    final Process pr = Runtime.getRuntime().exec(finalCommand);
    new Thread(new Runnable(){
    public void run() {
    BufferedReader br_in = null;
    try {
    br_in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
    String buff = null;
    while ((buff = br_in.readLine()) != null) {
    System.out.println("Process out :" + buff);
    try {Thread.sleep(100); } catch(Exception e) {}
    }
    br_in.close();
    }
    catch (IOException ioe) {
    System.out.println("Exception caught printing process output.");
    ioe.printStackTrace();
    }
    finally {
    try {
    br_in.close();
    } catch (Exception ex) {}
    }
    }
    }).start();

    new Thread(new Runnable(){
    public void run() {
    BufferedReader br_err = null;
    try {
    br_err = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
    String buff = null;
    while ((buff = br_err.readLine()) != null) {
    System.out.println("Process err :" + buff);
    try {Thread.sleep(100); } catch(Exception e) {}
    }
    br_err.close();
    }
    catch (IOException ioe) {
    System.out.println("Exception caught printing process error.");
    ioe.printStackTrace();
    }
    finally {
    try {
    br_err.close();
    } catch (Exception ex) {}
    }
    }
    }).start();
    }
    catch (Exception ex) {
    System.out.println(ex.getLocalizedMessage());
    }
    }

    public static boolean isWindows() {
    if (System.getProperty("os.name").toLowerCase().index Of("windows") != -1)
    return true;
    else
    return false;
    }

    };
    /

    CREATE OR REPLACE PROCEDURE PAS_HOST_COMMAND (p_command IN VARCHAR2)
    AS LANGUAGE JAVA
    NAME 'Host.executeCommand (java.lang.String)';
    /


    so this is what i run on sqlplus: don't know what null means...
    SQL> SET SERVEROUTPUT ON SIZE 1000000
    SQL> CALL DBMS_JAVA.SET_OUTPUT(1000000);

    Call completed.

    SQL> BEGIN
    2 PAS_HOST_COMMAND (p_command => 'c:\test.bat');
    3 end;
    4 /
    null

    PL/SQL procedure successfully completed.


    my test.bat is:
    move c:\test1.txt c:\test2.txt

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Apr 2006
    Posts
    2
    well that's on a unix environ which really doesn't help..

    how do i go about finding where the error is at when executing the store procedure??

  4. #4
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    You OBVIOUSLY did not BOTHER to actually read the section on how to do the same on Windoze.
    You're On Your Own (YOYO)!
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •