Home » RDBMS Server » Server Utilities » Execute an OS command using dbms_job
Execute an OS command using dbms_job [message #206196] Wed, 29 November 2006 02:46 Go to next message
reena_ch30
Messages: 100
Registered: December 2005
Senior Member
Hi,

How can i execute an OS command using dbms_job?

Thanks,
Reena
Re: Execute an OS command using dbms_job [message #206358 is a reply to message #206196] Wed, 29 November 2006 13:37 Go to previous messageGo to next message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
http://www.dbasupport.com/oracle/ora10g/dbms_scheduler.shtml
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:952229840241
Re: Execute an OS command using dbms_job [message #206399 is a reply to message #206196] Wed, 29 November 2006 22:36 Go to previous messageGo to next message
reena_ch30
Messages: 100
Registered: December 2005
Senior Member
Hi,

I am using oracle 9.2. How is it possible using dbms_job?

Thanks
Reena
Re: Execute an OS command using dbms_job [message #206430 is a reply to message #206399] Thu, 30 November 2006 00:47 Go to previous messageGo to next message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
Use the Java solution - then just submit the function/proc using dbms_job.submit. You must also commit before the jub will run.
Re: Execute an OS command using dbms_job [message #207333 is a reply to message #206196] Tue, 05 December 2006 02:55 Go to previous message
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
Previous Topic: Loading subtype with ref (ORA-22979)
Next Topic: How to get a db report in worddoc format??
Goto Forum:
  


Current Time: Wed Jul 03 10:07:34 CDT 2024