Operating System - OpenVMS
1753797 Members
7839 Online
108799 Solutions
New Discussion юеВ

java procedure call os command

 
SOLVED
Go to solution
ora_lion
Advisor

java procedure call os command

os: openvms
database: oracle 10g
i want call os command in plsql,the method is that:

conn / as sysdba
SQL> EXEC DBMS_JAVA.grant_permission('TEST', 'java.io.FilePermission', '<LES>>', 'read ,write, execute, delete');

PL/SQL procedure successfully completed.

SQL> EXEC Dbms_Java.Grant_Permission('TEST', 'SYS:java.lang.RuntimePermission',
'writeFileDescriptor', '');

PL/SQL procedure successfully completed.

SQL> EXEC Dbms_Java.Grant_Permission('TEST', 'SYS:java.lang.RuntimePermission',
'readFileDescriptor', '');

PL/SQL procedure successfully completed.

conn test/test

SQL> create or replace and compile
2 java source named "Util"
3 as
4 import java.io.*;
5 import java.lang.*;
6 public class Util extends Object
7 {
8 public static int RunThis(String args)
9 {
10 Runtime rt = Runtime.getRuntime();
11 int rc = -1;
12 try
13 {
14 Process p = rt.exec(args);
15 int bufSize = 4096;
16 BufferedInputStream bis =
17 new BufferedInputStream(p.getInputStream(), bufSize);
18 int len;
19 byte buffer[] = new byte[bufSize];
20 while ((len = bis.read(buffer, 0, bufSize)) != -1)
21 System.out.write(buffer, 0, len);
22 rc = p.waitFor();
23 }
24 catch (Exception e)
25 {
26 e.printStackTrace();
27 rc = -1;
28 }
29 finally
30 {
31 return rc;
32 }
33 }
34 }
35 /

Java created.

SQL>
SQL>
SQL> create or replace
2 function RUN_CMD(p_cmd in varchar2) return number
3 as
4 language java
5 name 'Util.RunThis(java.lang.String) return integer';
6 /

Function created.

SQL>
SQL>
SQL> create or replace procedure RC(p_cmd in varchar2)
2 as
3 x number;
4 begin
5 x := run_cmd(p_cmd);
6 end;
7 /

Procedure created.

set serveroutput on
exec dbms_java.set_output(100000);
exec rc('show sys');
exec dbms_java.grant_permission( 'TEST', 'SYS:java.io.FilePermission', '<>', 'execute' )
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:280)
at java.security.AccessController.checkPermission(AccessController.java:429)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:528)
at oracle.aurora.rdbms.SecurityManagerImpl.checkPermission(SecurityManagerImpl.java:192)
at java.lang.SecurityManager.checkExec(SecurityManager.java:778)
at java.lang.Runtime.exec(Runtime.java:563)
at java.lang.Runtime.exec(Runtime.java:428)
at java.lang.Runtime.exec(Runtime.java:364)
at java.lang.Runtime.exec(Runtime.java:326)
at Util.RunThis(Util:11)

PL/SQL procedure successfully completed.
the procedure successfully completed,but the os command not be called,
thank you for help me!!!!
7 REPLIES 7
ora_lion
Advisor

Re: java procedure call os command

I am sorry, the java source named "Util" is for windows or linux,i used it under openvms,so the result was wrong,but i want to use it under openvms system,anyone can help me? thank you.
x2084
Trusted Contributor

Re: java procedure call os command

It's not obvious (to me) what you are trying to do. I just want to point out what Java can execute: executable files.

In a Unix environment these are programs and (shell/perl...) scripts. In a VMS environment these are images and DCL command procedures.

You can not execute a Unix shell command or a VMS DCL command. For example, a VMS command "show sys" can not be executed from Java.

Other examples are "ls -l *.txt" or "DIR/FULL *.TXT". Both will not work if run from Java for the same reasons: both require a shell or DCL to be activated.

As a workaround, you may be able to run the command as a one-line input to the shell/DCL. On Unix this can be done with "sh -c \"ls -l *.txt\"". On VMS you may get it to work with the GNV DCL.EXE wrapper "gnu:[bin]dcl.exe \"DIR/FULL *.TXT\"".
Wim Van den Wyngaert
Honored Contributor
Solution

Re: java procedure call os command

ora_lion
Advisor

Re: java procedure call os command

my qustion is:
i want to execute openvms command such as $delete a.com;1 in plsql program
example:
SQL>exec exec_cmd('delete a.com')

how can i do this?
Wim Van den Wyngaert
Honored Contributor

Re: java procedure call os command

try "dcl.com delete a.com"

and create dcl.com with
$ 'p1' 'p2' 'p3' 'p4' ...

Check my link for "works".

Wim
Wim
ora_lion
Advisor

Re: java procedure call os command

Wim Van den Wyngaert:
thank you,i had solved the problem
ora_lion
Advisor

Re: java procedure call os command

1.
DCL.COM
$create/dir dkb0:[oracle.zm]

SQL>exec rc('@dkb0:[oracle]dcl');
then the directory zm is created.

2.
DCL.COM
$run $1$dga3:[USERS.LY]RMCOEFINIT
$@DCL //the RMCOEFINIT.exe can be executed.

but
SQL>exec rc('@dkb0:[oracle]dcl');
the RMCOEFINIT.exe can't be executed.
how can i execute the exe file.