We help IT Professionals succeed at work.
Get Started

Error No such file or Directory when calling shell command line by Java source in Oracle

HelloKitty2011
on
578 Views
Last Modified: 2013-12-18
I need to call sh script to run a abcProcess.jar (created in java). the shell script name is runjar.sh. the content of the /usr2/RPM/runjar.sh is below:
   

runjar.sh
#!/bin/sh
/usr2/abc/java/bin/java -jar "abcProcess.jar" "DEV" "10000" "1" "261" "myuser"
     

 after i created the java and proc (see step 1 and 2) in my current xyz schema from Burleson's sample codes, and and try to run it (step 3)  as the following, I got  error messages:
it seems permisssion but i still has no clue what caused it. the runjar.sh   did exist in this /usr2/XYZ/ directory. any advise? why i got this error: No such file or directory

   
step1 : here is the java source:
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];
        finalCommand[0] = "C:\\winnt\\system32\\cmd.exe";
        finalCommand[1] = "/y";
        finalCommand[2] = "/c";
        finalCommand[3] = command;
      }
      else {
        finalCommand = new String[1];
        //finalCommand[0] = "/bin/sh";
        //finalCommand[1] = "-c";
        finalCommand[0] = command;
      }

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

     
     
    }
    catch (Exception ex) {
        System.out.println("localizemessage: "+ex.getMessage());

      System.out.println(ex.getLocalizedMessage());
    }
  }
 
  public static boolean isWindows() {
    if (System.getProperty("os.name").toLowerCase().indexOf("windows") != -1)
      return true;
    else
      return false;
  }

};
/

step 2: here to publish the java source:
CREATE OR REPLACE PROCEDURE host_command (p_command  IN  VARCHAR2)
AS LANGUAGE JAVA
NAME 'Host.executeCommand (java.lang.String)';
/


Error after runing step 3 below
Method called.
run
err
exec failed: /usr2/XYZ/runjar.sh, No such file or directory
PL/SQL procedure successfully completed.


step 3: to test from toad
SET SERVEROUTPUT ON SIZE 1000000
CALL DBMS_JAVA.SET_OUTPUT(1000000);
 DECLARE
  P_COMMAND VARCHAR2(32767);
   
BEGIN
  P_COMMAND := '/usr2/XYZ/runjar.sh';

  XYZ.HOST_COMMAND ( P_COMMAND );
  COMMIT;
END;

`
Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 12 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE