Oracle (11gr2) calling unix commands (aix)

I have an Oracle database running on AIX, and I have a procedure that is calling OS commands from an oracle (and it's not working anymore)...

so, there was an Java stored proc in Oracle

CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED COMMON."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[0];
//finalCommand[0] = "/bin/sh";
//finalCommand[1] = "-c";
//finalCommand[2] = command;
finalCommand[0] = "/bin/sh -c '" + command + "'";
}

final Process pr = Runtime.getRuntime().exec(finalCommand);
pr.waitFor();
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().indexOf("windows") != -1)
return true;
else
return false;
}
};
/

and a procedure that calls it:

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

and it was working by calling (for example):

begin
common.host_command('/usr/bin/pwd > /tmp/abc123');
end;

now, it's not working... it's dead...

is it because we deleted extproc from a listener.ora?

It might be a permission problem - did you grant the appropriate Java permission to the schema owner ?

Also, check for messages in your trace file. Log in to SYS or any user that has DBA privileges and -

show parameter user_dump_dest

Then change to the directory (specified in the VALUE column) and check if there are any "*.trc" files generated after you run your anonymous PL/SQL block. It should tell you what's wrong.

If there are no "trc" files then we really don't know that it is running.

tyler_durden