Call OS Command from Database

How Can I call a OS Command from database stored procedure. From Developer I use host command.
Thanks

You can use java stored procedures for this purpose if you are using Oracle8i.
Here is some sample code for doing this.
import java.io.*;
import java.util.*;
public class ExecDemo {
static public String[] runCommand(String cmd)
throws IOException {
// set up list to capture command output lines
ArrayList list = new ArrayList();
// start command running
Process proc = Runtime.getRuntime().exec(cmd);
// get command's output stream and
// put a buffered reader input stream on it
InputStream istr = proc.getInputStream();
BufferedReader br =
new BufferedReader(new InputStreamReader(istr));
// read output lines from command
String str;
while ((str = br.readLine()) != null)
list.add(str);
// wait for command to terminate
try {
proc.waitFor();
catch (InterruptedException e) {
System.err.println("process was interrupted");
// check its exit value
if (proc.exitValue() != 0)
System.err.println("exit value was non-zero");
// close stream
br.close();
// return list of strings to caller
return (String[])list.toArray(new String[0]);
public static void main(String args[]) throws IOException {
try {
// run a command
String outlist[] = runCommand("/bin/ls -l");
//String outlist[] = runCommand("/u02/home/usupport/ashehade/java/test");
// uncomment this line an comment above if you want to execut
// a c executable called test.
// display its output
for (int i = 0; i < outlist.length; i++)
System.out.println(outlist);
catch (IOException e) {
System.err.println(e);
Load this to the datbase
loadjav -u scott/tiger ExecDemo.java
Publish the proceduer
create or replace procedure lsfromjava as
language java name 'ExecDemo.main(java.lang.String[])';
Test it
SQL> set serverout on
SQL call dbms_java.set_output(2000);
SQL> execute lsfromjava
total 1770
-rw-r--r-- 1 usupport udba 8385 Aug 27 1999 init.ora
-rwxr-xr-x 1 usupport udba 1724 Mar 14 05:46 initCONV.ora
lrwxrwxrwx 1 usupport udba 45 Mar 10 11:01 initMWS2.ora ->
/u03/app/oracle/admin/MWS2/pfile/initMWS2.ora
lrwxrwxrwx 1 usupport udba 59 Jan 11 16:09 initV816.ora ->
/u02/app/oracle/product/8.1.6/admin/V816/pfile/initV816.ora
-rw-r--r-- 1 usupport udba 9219 Aug 27 1999 initdw.ora
lrwxrwxrwx 1 usupport udba 59 Feb 14 11:55 initreid.ora ->
/u02/app/oracle/product/8.1.6/admin/reid/pfile/initreid.ora
-rw-r--r-- 1 usupport udba 835 Nov 3 17:07 initsoxx.sql
-rw-rw---- 1 usupport udba 24 Mar 13 10:22 lkBLEVE
-rw-rw---- 1 usupport udba 24 Mar 14 05:46 lkCONV
-rw-rw---- 1 usupport udba 24 Mar 13 04:48 lkMWS2
If you are using Oracle 8.0.5 , then you can use external procedures for this.
There was one article in the Oracle Magazine for doing this with external procedures. You can search the archives for this purpose.

Similar Messages

  • Call Unix Command From Reports Using Java

    Hi,
    Could somebody please show me a sample coding to call Unix command from 10g report using java?
    In metalink doc id 361857.1 does not show much.
    Thanks,
    neemin

    Hi,
    I have a problem with synchronization of the java commands.
    In the Before Parammeter Form trigger, I have:
    function BeforePForm return boolean is
    rt ORA_JAVA.JOBJECT;
    proc ORA_JAVA.JOBJECT;
    v_txt varchar2(32000);
    i integer := 0;
    v_cd_modulo int;
    v_arqlog text_io.file_type;
    cursor c_evento is
    select codigo,
    nome
    from
    (select e.cd_evento || e.cd_edicao codigo
    ,nm_evento nome
    from grh_ev_evento e
    where e.CD_GRUPO in (select cd_grupo
    from grh_ev_adm
    where cd_usuario = (select cd_usuario
    from usuario
    where login_usuario = :AUTHID)))
    order by substr(nome, 11);
    begin
    -- Create the context for logged user
    if instr(upper(nvl(:AUTHID,'RWCLIENT')),'RWCLIENT') > 0 then
    :AUTHID := :SSO_USUARIO;
    end if ;
    TCEENV.SET_TCEENV(:AUTHID);
    if PK_SCA.SCA_GET_USER_RIGHTS(:sca_module_name, :AUTHID) IS NULL then
    srw.message(100, 'Access denided!');
    return (FALSE);
    end if;
    -- Create file in Report Server (UNIX)
    v_txt := '<BR>' || htf.formSelectOpen('P_EV_EDICAO', 'Evento: ');
    :p_file := '/u03/SCAWEB/repout/' || :sca_module_name || '_' ||
    pk_sca.sca_encrypt(:AUTHID || to_char(systimestamp, 'ss.ff'));
    v_arqlog := text_io.fopen (:p_file, 'A');
    text_io.put_line (v_arqlog, v_txt);
    for reg in c_evento loop
    i := i + 1;
    if i = 1 then
    v_txt := '<OPTION SELECTED VALUE="' || reg.codigo || '">' || reg.nome;
    else
    v_txt := '<OPTION VALUE="' || reg.codigo || '">' || reg.nome;
    end if;
    text_io.put_line (v_arqlog, v_txt);
    end loop;
    v_txt := '</SELECT></CENTER></form></BODY> </HTML>';
    text_io.put_line (v_arqlog, v_txt);
    text_io.fclose (v_arqlog);
    SRW.SET_AFTER_FORM_HTML(SRW.FILE_ESCAPE, :p_file);
    rt := RUNTIME.GetRuntime();
    proc := RUNTIME.exec(rt,'rm ' || :p_file);
    return (TRUE);
    end;
    The problem is that there isn't a "synchronize" command, and the
    RUNTIME.exec(rt,'rm ' || :p_file) don't works (it does nothing) because
    the SRW.SET_AFTER_FORM_HTML has a large delay and the following
    command is ignored.
    How can I solve it?
    thanks,
    lmprestes

  • How to call gnuplot command from java

    Hi there,
    In our course, we are required to develop an GUI for gnuplot. In case you don't know about gnuplot, it's a plotting program and has lots of command. We want to use java and swing, but now we don't know how to call gnuplot command from java, or how to execute a shell command(script) from java.
    By the way, since we need read in files with several columns of data and allow user to select a column, we want to use JTable. Is that reasonable?
    Thanks a lot for any suggestions!
    Jack

    Hi, there:
    Will using JTable add much overhead? I may have to use several JTables and switch among them. I can add scroll bar to or edit JTables, right?
    BTW, do you have experience about gnuplot? Can I find the command tree of gnuplot somewhere? Or do you know a better place to post question about gnuplot? unix/linux group, maybe.
    Thanks,
    Jack
    P.S. Would you guys answer my question after I use up my duke dollars? :- )

  • How can I call a Report From database function

    Hi all,
    I want to call a Report from a database function. Could you hel
    me???
    Rgds

    Hello there!
    There is a solution for executing an executable like RWRUN60
    from PL/SQL on http://asktom.oracle.com/pls/ask/f?
    p=4950:8:227101::NO::F4950_P8_DISPLAYID,F4950_P8_B:150612348067,Y
    Or you can invoke the CGI from the Reports-Server through
    UTL_HTTP
    Hope this helps
    Dannys

  • Calling Web Service from Database

    Hello,
    we want to call a Web Service from Database. What will we need or what must we install to do this. We're using a 10g Database.
    Best regards ,
    Goronja

    Hello,
    This feature is called "Database Web Services Call Out" and documented in:
    - Developing a Web Service Client in the Database
    Regards
    Tugdual Grall

  • Calling Host Command Through Database  Procedures or Triggers

    We are intreseted to run the O/S command through Database stored procedures
    or triggers.
    Pl. help

    You can even see the STDOUT and STDERR for your commands that you run from inside the database. An example can be found here
    http://www.ckamco.com/Execute_Command.zip
    Good Luck,
    Eric Kamradt

  • How to call a procedure from database executing commandButton...

    Hello.
    I´m using Jdev 10.1.3.2, I´d like to know how can I execute a procedure from database when I click a command button..??
    is that possible?
    thanks again.

    Yes, it's possible.
    Since you don't say anything about technologies you are using, I will assume ADF Business Components and JSF.
    You can write a service method in your application module - see Section 25.5 of the ADF Developer's Guide for Forms/4GL Developers
    Then, you can drag-and-drop the service method from the data control palette on to your JSF page and select ADF Command Button when you drop.
    You will, in all likelyhood, find numerous examples when you search the forum as well.
    John

  • Sending down Linux commands from database

    Hello
    Im working with Oracle 10.2.0.4.3 on Linux SuSE FUSE Version 2.3.0-RC0-SL0/SLES-9.
    Im currently doing an extract of BLOB files down to a directory on the server.
    When I do the extract the Oracle user becomes the owner of the files and my own user doesn't have the access (neither read or write) to the files.
    I cannot receive Oracle access due a security issue so Im wondering if its possible to send down a command from the database that does a
    $chmod a+rw my_directory/*.* ?
    Iv looked into the some forums and I didnt find anything in particulate that would help me, so Im wondering if any of you know if this is possible ?
    BR / SA

    Hello
    Thank you for your advice but the question was to send down Linux commands from the DB, not do anything in the Linux enviroment.
    Here is a good place to start that I found on the net.
    public class JShellCommand {
    public static int execute(String cmd) {
    try
    String[] shellCmd = { "/bin/sh", "-c", cmd };
    Process process = Runtime.getRuntime().exec(shellCmd);
    int exitVal = process.waitFor();
    return (exitVal);
    catch (Exception e)
    return 1;
    load it into db with loadjava and wrap it with:
    CREATE OR REPLACE
    FUNCTION Shell_Command(
    p_CMD IN VARCHAR2
    RETURN NUMBER
    AS
    LANGUAGE JAVA
    NAME 'JShellCommand.execute(java.lang.String) return int';
    For OS command you can use:
    public class JCommand {
    public static int execute(String cmd) {
    try
    Process process = Runtime.getRuntime().exec(cmd);
    int exitVal = process.waitFor();
    return (exitVal);
    catch (Exception e)
    return 1;
    and
    CREATE OR REPLACE
    FUNCTION OS_Command(
    p_Cmd IN VARCHAR2
    RETURN NUMBER
    AS LANGUAGE JAVA
    NAME 'JCommand.execute(java.lang.String) return int';
    /

  • Call unix commands from stored procedures

    My stored procedure requires to call unix commands HOW DO I DO IT?
    null

    i do not know pl sql but in java you can use:
    Runtime.getRuntime().exec("YOUR UNIX COMMAND");
    real example:
    Runtime.getRuntime().exec("ls");
    but you must be careful with using that...
    especially if you want to wait till the process finishes..
    rgds,

  • Error received when calling web service from database.

    Hi folks,
    I am trying to call a web service from the database (using the Oracle database web services call-out utility) and I am getting the following error:
    ERROR at line 1:
    ORA-29532: Java call terminated by uncaught Java exception:
    java.rmi.RemoteException:
    oracle.j2ee.ws.common.encoding.DeserializationException:unknown prefix in QName
    literal: null
    ORA-06512: at "SCOTT.PENALTY_ALG_WS_WRAPPER", line 1
    ORA-06512: at "SCOTT.ABC_PROC", line 131
    ORA-06512: at line 1
    This is the error I see in the trace file on the database:
    *** 2009-11-10 11:30:37.353
    java.rmi.RemoteException: oracle.j2ee.ws.common.encoding.DeserializationException:unknown prefix in QName literal: null
         at oracle.j2ee.ws.common.encoding.simpletype.XSDQNameEncoder.stringToObject(XSDQNameEncoder.java:75)
         at oracle.j2ee.ws.common.encoding.SimpleTypeSerializer.deserialize(SimpleTypeSerializer.java:141)
         at oracle.j2ee.ws.common.encoding.SOAPFaultInfoSerializer.doDeserializeSOAP11(SOAPFaultInfoSerializer.java:120)
         at oracle.j2ee.ws.common.encoding.SOAPFaultInfoSerializer.doDeserialize(SOAPFaultInfoSerializer.java:94)
         at oracle.j2ee.ws.common.encoding.ObjectSerializerBase.deserialize(ObjectSerializerBase.java:180)
         at oracle.j2ee.ws.client.StreamingSender._readBodyFaultElement(StreamingSender.java:513)
         at oracle.j2ee.ws.client.StreamingSender._sendImpl(StreamingSender.java:321)
         at oracle.j2ee.ws.client.StreamingSender._send(StreamingSender.java:112)
         at genproxy.runtime.PenaltyAlgBPELProcessBinding_Stub.process(genproxy.runtime.PenaltyAlgBPELProcessBinding_Stub:80)
         at genproxy.PenaltyAlgBPELProcessPortClient.process(PenaltyAlgBPELProcessPortClient.java:40)
         at genproxy.PenaltyAlgBPELProcessPortClientJPub.process(PenaltyAlgBPELProcessPortClientJPub.java:46)
    This web service is deployed on Oracle app server 10.1.3.4. It calls a BPEL process which in turn calls Oracle Business Rules.
    I used JPublisher to create the stubs for the web service and load them into the database.
    Any ideas on what might be causing this error?
    Thanks.
    Kashif

    Well, I think so... I've followed all the steps, and my merged WSDL file seems like the one in page 12...
    Any suggestion, please?
    Thank you,

  • How to call TimesTen "command" from program

    I m trying to call command "dssize" from my java program.
    I can call any built in procedure with callable statement, but for "dssize" is not working. is that possible?
    Thank you and best regards.

    'dssize' is a ttIsql command and so cannot be called from an application. The information reported by dssize comes from various columns in the SYS.MONITOR table. All you need to do is SELECT those columns and use the values.
    Chris

  • Calling UNIX command from PL/SQL Procedure

    Is there a way to call a UNIX command (exa. ls) from within a PL/SQL stored procedure? Looking through the various packages, I didn't see anything that would give me this ability.
    I also looked through all the previous questions and nothing looked encouraging.
    Thanks in advance,
    Russ

    Russ,
    I thought I'd read a similar question awhile ago and did a search on the word host in this forum and found the following from July 9th that might help you:
    http://technet.oracle.com:89/ubb/Forum88/HTML/001611.html
    In that post I think the link listed by Barbara Boehmer in has changed to:
    ]http://asktom.oracle.com/pls/ask/f?p=4950:8:24579::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:16212348050,{host}
    It looks like they give solutions for Oracle 7, 8 and 8i.
    Good site Barbara, I've added it to my bookmarks.
    Hope this helps.

  • Calling Unix command from the plsql

    Hi ,
    I am executing java code from the UNIX Shell script. Before executing this command i want to write plsql code to and pass the files to java command.
    In the plsql code i want to select request id's using the cursor and find the .out files for each request id in the outfile path. once the file is found i want to copy that .out file to the current directory where the java command is going to execute.
    Please suggest me how to use UNIX Command (in my case "cp") to copy the .out file from the outfile path to current directory after opening the cursor.

    If I understand you correctly, you want to generate a log of request id's from the database and send this to the operating system whereby you will execute the following:
    <p>
       <font face="courier">java org.apache.xalan.xslt.Process -XSL combinedfsg.xsl -OUT output.xml</font>
    <p>
    If that is correct, then you should be able to perform all of this w/ PL/SQL by generating the log from the database and write it to the O/S w/ UTIL_FILE. If you want to execute the java code at this point, you should be able to utilize Tom's method with the following:
    <p>
       <font face="courier">exec rc('java org.apache.xalan.xslt.Process -XSL combinedfsg.xsl -OUT output.xml');</font><p>

  • Calling DOS command from a webpage?

    How would I go about doing this? I want a webpage that when an image is clicked this DOS command is called:
    rundll32.exe C:\WINDOWS\System32\shimgvw.dll,ImageView_Fullscreen Image_Location\image.jpgThis command opens the image in Windows Picture and Fax Viewer. I'm not worried about portability since this is only going to be on my home network. I figure I'll probably need Java or something to do this, but I've no clue where to start looking. Help is appreciated!

    How would I go about doing this? I want a webpage
    that when an image is clicked this DOS command is
    called:First of all, this is not a Java-related question. It is an HTML and browser capabilities question.
    Second of all, in general this is not possible. If it were, imagine the security issues allowing a web page to arbitrarily allow executing anything on the client victim's machine. At best the user has to configure his browser to "trust" content from the site in question. Since you as the application provider can't force this configuration to happen automatically, you're out of luck unless you are in complete control over the clients (such as if they are all within the corporate intranet only).

  • Calling wlst commands from utility script?

    Hi all,
    I'm trying to write some utility functions to wrap things like create() and delete() with some error handling code. So I would have a module like utils.py and it would contain methods like myDelete(), myCreate(), etc. I would like them to then call WLST's delete() and create(). Then I would have a script that creates and deletes queues, for example, that would use utils.myDelete() etc. However this doesn't work and I can't figure out why.
    If I just reference the wlst commands directly, I get "Name Error: cd."
    If I import
    from weblogic.management.scripting import WLScriptContext as wlst
    WLST = wlst()
    I get "... Unknown error...Use dumpStack()..." But dumpStack()'s output is empty.
    If I extract wlstModule.py from the jar file and try importing it, I get "no module named wlstModule."
    Suggestions?
    thanks

    Hello John,
    Here are the steps you can follow to import wlst into other jython modules.
    Extract wlstModule.py from the jar or you can also use the command writeIniFile(<file-path>) for WLST to write out the module file. Place wlstModule.py in the directory where you are going to invoke jython from or where you have your other utility scripts. In your utility script you should import the module as
    import wlstModule
    And in the script wherever you would like to call any wlst commands you should use wlstModule.<command>. Also use straight jython while invoking the scripts as
    java org.python.util.jython instead of java weblogic.WLST.
    Thanks,
    -satya
    BEA Blog: http://dev2dev.bea.com/blog/sghattu/

Maybe you are looking for

  • AirPlay Mirroring not available on my new macbook pro

    My Macbook Pro is two days old and does not support mirroring to my ATV2??? My iPAD1, my iPhone 4's all do...whats up? Am I missing something? Mountain Lion, Intel 2.9 Ghz, 8 Gb RAM? Please help.

  • Protege Plugin Problem

    I think the sample Protege plugin Oracle provides breaks Protege 3.2.1 - I downloaded it here: http://download.oracle.com/otn/other/semantic_tech/protege_oracle_rdf_plugin.zip I made a fresh install of Protege, created an oracle directory in the plug

  • New symbol instead of wifi, since update

    since updating to 2.1 when my wifi is off there is a tiny little circle instead anyone know what it is??

  • Individual Object assigned 2 Reference Product

    I want to use Individual Object with referencing Data from Products in CRM 5.0 SAPGUI. Help link CRM 5.0: http://help.sap.com/saphelp_crm50/helpdata/en/a9/42388d7cb5c24ba5a3701a13aa9ea4/frameset.htm The steps I made: In trx COMM_HIERARCHY I added the

  • Add Number to Harddrive Name?

    I've always been curious as to why OSX changes the name of my harddrive every now and then, adding the next integer to the name. My network name changed from Alex to Alex 2 and is now up to Alex 6. Restoring the system doesn't seem to do anything. It