Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to get return value from Java runtime.getRuntime.exec?

770799Sep 22 2010 — edited Sep 22 2010
I'm running shell commands from an Oracle db (11gr2) on aix.
But, I would like to get a return value from a shell comand... like you get with "echo $?"

I use a code like
CREATE OR REPLACE JAVA SOURCE NAMED common."Host" AS
import java.io.*;
public class Host {
  public static int executeCommand(String command) {
    int retval=0;
    try {
        String[] finalCommand;
        finalCommand = new String[3];
        finalCommand[0] = "/bin/sh";
        finalCommand[1] = "-c";
        finalCommand[2] = command;

      final Process pr = Runtime.getRuntime().exec(finalCommand);
      pr.waitFor();
}
   catch (Exception ex) {
      System.out.println(ex.getLocalizedMessage());
      retval=-1;
    }
    return retval;
};
/
but I do not get a return value... because I don't know how to get return value..

Edited by: user9158455 on 22-Sep-2010 07:33
This post has been answered by Peter Gjelstrup on Sep 22 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 20 2010
Added on Sep 22 2010
3 comments
3,415 views