Skip to Main Content

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Gaurang.

Asked: September 29, 2001 - 5:43 pm UTC

Last updated: October 02, 2001 - 10:51 am UTC

Version: 8.1.7

Viewed 1000+ times

You Asked

hi tom,

I want to run OS command and i am following your code that
you answered previously.

i am running this dbms_java for permission

I am using personal oracle on windows 98.

begin
dbms_java.grant_permission
( user,
'java.io.FilePermission',
'/usr/bin/ls',
'execute');

dbms_java.grant_permission
(user,
'java.lang.RuntimePermission',
'*',
'writeFileDescriptor' );
end;
/
PL/SQL procedure successfully completed.

I am getting this error message

SQL> exec rc('dir');
java.security.AccessControlException: the Permission (java.io.FilePermission
<<ALL FILES>> execute) has not been granted by dbms_java.grant_permission to
SchemaProtectionDomain(SCOTT|PolicyTableProxy(SCOTT))
at java.security.AccessControlContext.checkPermission(AccessControlContext.java)
at java.security.AccessController.checkPermission(AccessController.java)
at java.lang.SecurityManager.checkPermission(SecurityManager.java)
at
oracle.aurora.rdbms.SecurityManagerImpl.checkPermission(SecurityManagerImpl.java
)
at java.lang.SecurityManager.checkExec(SecurityManager.java)
at java.lang.Runtime.exec(Runtime.java)
at java.lang.Runtime.exec(Runtime.java)
at java.lang.Runtime.exec(Runtime.java)
at Util.RunThis(Util:11)

PL/SQL procedure successfully completed.


Thanks

I am using personal oracle on windows 98.

and Tom said...

dir is not a program. there is no "dir.exe"

You would have to run cmd.exe or command.exe or whatever and pass it "/c dir" to have it run the command HOWEVER - i would advise strongly AGAINST that as you would have to allow this user to run cmd.exe which in effect allows them to RUN ANYTHING since they can just go "cmd /c anyprogram".

Try your tests with an actual "executable"

Rating

  (3 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Why not just use the HOST function?

A reader, October 02, 2001 - 6:28 am UTC

Why not just use the HOST function in SQL*Plus instead of going through all the trouble?

Tom Kyte
October 02, 2001 - 7:42 am UTC

Because the host command is a SQL*Plus, not a PLSQL command, and people want to run programs from their stored procedures -- not using SQLPlus.

If you are using SQL*Plus, the host command is the proper way to do it.

If you need to run a command on the server via a stored procedure, SQL*plus does not do it at all.

A reader, October 02, 2001 - 10:35 am UTC

hi tom,

can i run SQLLDR like

rc('SQLLDR XYZ/XYZ@ORACLE CONTROL= .. ')

Thanks

Tom Kyte
October 02, 2001 - 10:41 am UTC

yes. sqlldr is a program so it can be run via this method.

A reader, October 02, 2001 - 10:51 am UTC

hi tom,

can i run SQLLDR like

rc('SQLLDR XYZ/XYZ@ORACLE CONTROL= .. ')

Thanks

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library