|
|
|
|
Re: Execute an OS command using dbms_job [message #207333 is a reply to message #206196] |
Tue, 05 December 2006 02:55 |
reena_ch30
Messages: 100 Registered: December 2005
|
Senior Member |
|
|
Hi,
I tried the java option. Following is the code to run an executable e.g Windows calendar
CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "OSCommand" AS
import java.io.*;
public class OSCommand{
public static String Run(String Command){
try{
Runtime.getRuntime().exec(Command);
return("0");
}
catch (Exception e){
System.out.println("Error running command: " + Command +
"\n" + e.getMessage());
return(e.getMessage());
}
Java created.
SQL> CREATE or REPLACE FUNCTION OSCommand_Run(Command IN STRING)
2 RETURN VARCHAR2 IS
3 LANGUAGE JAVA
4 NAME 'OSCommand.Run(java.lang.String) return int';
5 /
Function created.
Execute dbms_java.grant_permission( 'SCOTT','SYS:java.io.FilePermission', '<<ALL FILES>>','execute');
execute dbms_java.grant_permission( 'SCOTT','SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '*' );
execute dbms_java.grant_permission( 'SCOTT','SYS:java.lang.RuntimePermission', 'readFileDescriptor', '*' );
Now when i execute the function, it returns 0 and completes successfully, but the executable is not opened. how to do that??
SQL> Declare
2 x Varchar2(2000);
3 Begin
4 x := OSCommand_Run('c:\windows\system32\calc');
5 DBMS_OUTPUT.Put_Line(x);
6 End;
7 /
0
PL/SQL procedure successfully completed.
Thanks
Reena
|
|
|