How to call a host command/program within a PL/SQL Procedure OR Block

Hello ,
I want to call a host program (in my case it is unix shell program) from within a PL/SQL
Procedure..Please let me know if you have a clue...Thanks a bunch...Ajeet

Alternatively you could create a PL/SQL procedure that wraps a Java Runtime object.
You can find an example of this in the Ask Tom column of Oracle Magazine. You can get there from OTN home page. Type "Java Runtime" into the Search Archive engine.
HTH, APC

Similar Messages

  • PL/SQL Procedure Calling Java Host Command Problem

    This is my first post to this forum so I hope I have chosen the correct one for my problem. I have copied a java procedure to call Unix OS commands from within a PL/SQL procedure. This java works well for some OS commands (Eg ls -la) however it fails when I call others (eg env). Can anyone please give me some help or pointers?
    The java is owned by sys and it looks like this
    CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "ExecCmd" AS
    //ExecCmd.java
    import java.io.*;
    import java.util.*;
    //import java.util.ArrayList;
    public class ExecCmd {
    static public String[] runCommand(String cmd)
    throws IOException {
    // set up list to capture command output lines
    ArrayList list = new ArrayList();
    // start command running
    System.out.println("OS Command is: "+cmd);
    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: "+proc.exitValue());
    // 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(args[0]);
    for (int i = 0; i < outlist.length; i++)
    System.out.println(outlist);
    catch (IOException e) {
    System.err.println(e);
    The PL/SQL looks like so:
    CREATE or REPLACE PROCEDURE RunExecCmd(Command IN STRING) AS
    LANGUAGE JAVA NAME 'ExecCmd.main(java.lang.String[])';
    I have granted the following permissions to a user who wishes to run the code:
    drop public synonym RunExecCmd
    create public synonym RunExecCmd for RunExecCmd
    grant execute on RunExecCmd to FRED
    grant javasyspriv to FRED;
    Execute dbms_java.grant_permission('FRED','java.io.FilePermission','/bin/env','execute');
    commit
    Execute dbms_java.grant_permission('FRED','java.io.FilePermission','/opt/oracle/live/9.0.1/dbs/*','read, write, execute');
    commit
    The following test harness has been used:
    Set Serverout On size 1000000;
    call dbms_java.set_output(1000000);
    execute RunExecCmd('/bin/ls -la');
    execute RunExecCmd('/bin/env');
    The output is as follows:
    SQL> Set Serverout On size 1000000;
    SQL> call dbms_java.set_output(1000000);
    Call completed.
    SQL> execute RunExecCmd('/bin/ls -la');
    OS Command is: /bin/ls -la
    total 16522
    drwxrwxr-x 2 ora9sys dba 1024 Oct 18 09:46 .
    drwxrwxr-x 53 ora9sys dba 1024 Aug 13 09:09 ..
    -rw-r--r-- 1 ora9sys dba 40 Sep 3 11:35 afiedt.buf
    -rw-r--r-- 1 ora9sys dba 51 Sep 3 09:52 bern1.sql
    PL/SQL procedure successfully completed.
    SQL> execute RunExecCmd('/bin/env');
    OS Command is: /bin/env
    exit value was non-zero: 127
    PL/SQL procedure successfully completed.
    Both commands do work when called from the OS command line.
    Any help or assistance would be really appreciated.
    Regards,
    Bernard.

    Kamal,
    Thanks for that. I have tried to use getErrorStream and it does give me more info. It appears that some of the commands cannot be found. I suspected that this was the case but I am not sure about how this can be as they all appear to reside in the same directory with the same permissions.
    What is more confusing is output like so:
    SQL> Set Serverout On size 1000000;
    SQL> call dbms_java.set_output(1000000);
    Call completed.
    SQL> execute RunExecCmd('/usr/bin/id');
    OS Command is: /usr/bin/id
    exit value was non-zero: 1
    id: invalid user name: ""
    PL/SQL procedure successfully completed.
    SQL> execute RunExecCmd('/usr/bin/which id');
    OS Command is: /usr/bin/which id
    /usr/bin/id
    PL/SQL procedure successfully completed.
    Regards,
    Bernard

  • How to call Operating System commands / external programs from within APEX

    Hi,
    Can someone please suggest how to call Operating Systems commands / external programs from within APEX?
    E.g. say I need to run a SQL script on a particular database. SQL script, database name, userid & password everything is available in a table in Oracle. I want to build a utility in APEX where by when I click a button APEX should run the following
    c:\oracle\bin\sqlplusw.exe userud/password@database @script_name.sql
    Any pointers will be greatly appreciated.
    Thanks & Regards,

    Hi Guys,
    I have reviewed the option of using scheduler and javascript and they do satisfy my requirements PARTIALLY. Any calls to operating system commands through these features will be made on the server where APEX is installed.
    However, here what I am looking at is to call operating systems programs on client machine. For example in my APEX application I have constructed the following strings of commands that needs to be run to execute a change request.
    sqlplusw.exe user/password@database @script1.sql
    sqlplusw.exe user/password@database @script2.sql
    sqlplusw.exe user/password@database @script3.sql
    sqlplusw.exe user/password@database @script4.sql
    What I want is to have a button/link on the APEX screen along with these lines so that when I click that link/button this entire line of command gets executed in the same way it would get executed if I copy and paste this command in the command window of windows.
    Believe me, if I am able to achieve what I intend to do, it is going to save a lot of our DBAs time and effort.
    Any help will be greatly appreciated.
    Thanks & Regards,

  • How to call a Standard SAP Program in Zprogram.

    Hi,
    how to call a SAP Standard program in SAP Program?
    Do we have to use any funtion module and pass paramters?
    I want to call a Standard SAP prg in to my prgram? can anyone explain me or give the piece of code to call standard prg.
    Thanks & Regards

    Again, ABAP related questions should be asked in the ABAP forum.
    To answer you question,  if the standard program is a report program, you can use the SUBMIT statement and pass parameters using the WITH Extention.
    Submit <report>
          with p_fld = 'X'
              and return.
    Please make sure to award points for helpful answers and mark your posts as solved when solved completely.  Thanks.
    Regards,
    RIch Heilman

  • Calling a Host Command

    Dear Friends,
    Is it posible to call a host command (windows) from PLSQL (Oracle 9i) ?
    Thanks.
    Jai

    > [email protected]
    [email protected]
    [email protected]
    So.. the one who dies with the most e-mail addresses wins?
    Or what exactly is the purpose of posting all your e-mail addresses - besides as food for web bot e-mail harvesters used by spammers?

  • How to call unix script/command in ODI

    Hello Gurus,
    Please let me know how to call unix script/command in ODI?
    Thanks
    Shridhar

    you can call shell script using the OS command found in Package.
    Step 1. Drag the OS Command in the Packgae
    Step 2. In the Text mentiond call the script say for ex sh /opt/path/script.sh
    Step 3. Execute.
    Note : Make sure the User through which ODI is triggering does have the required permission to execute shellscript , also always provide the full path , since scripts are execute from the oracldi/bin folder so its necessary to provide the complete path of the script location.
    Hope this helps.

  • How to run a HOST command from Report 2.5

    Hello everybody,
    I want to pass an unix command from a Report. I am running the report (Report 2.5) on an Unix server and I want to pass a unix host command inside the Before Report Trigger of the report. But Report2.5 is not recognising the HOST built-in. Is there is any way around?
    Thank in advance.
    Samujjwal Basu

    First off is that openssl command correct? Should it be this instead:
    openssl pkcs8 -inform der -nocrypt -in test.der -out result.pem
    Try out your openssl command within a command prompt so that you know that it works ok. I think the command line you specified waits on stdin (well it does for me).
    After that.....
    runtime.exec creates a Process object. If you do this:
    Process openssl = runtime.exec("....")
    then you can examine the return code from openssl to see the exit code - for instance if the input file does not exist then exit = 1. You can test for this with Java
    Alternatively you could get the stderr from the process and look inside it - if it is 0 length then all is good, if it has some text in there then it has likely failed. You could then throw an exception and include the stderr output in the exception messgae. You may need to experiment with this, runnig it first when openssl is happy then running it again when openssl is upset.
    M

  • Calling java host command in trigger/PLSQL

    I created a java call to execute a linux host command that calls a shell script that will echo out a result. It is owned by SYS and has granted execute to SYSTEM. SYSTEM has a table that monitors accesses to the RDBMS. When a user logs on from a remote server vis sqlplus, this LOGON trigger write to the SYSTEM table (successfully). SYSTEM has a trigger that runs a linux command to execute a shell script that pulls the actual IP address from the remote system. I can run this call from a PLSQL block (outside the trigger) and get a response back like "user:101.101.101.111" but when I have the same user log on, the trigger fires - no errors or exceptions yet no rows are returned. Is there some restriction in a trigger versus just a plsql block call? The java code used is what I found on (http://www.oracle-base.com/articles/8i/ ... mPLSQL.php) and it works perfectly OUTSIDE the trigger but nothing is returned in the trigger firing steps. Any idea?
    rdbms: 11.1.0.7, Redhat 4
    I know the code works because I can write the host command output to a file. Later in the trigger I can open the file and can read the data that should have been returned in the java host call.

    FYI - here is the code from your site that I used:
    DROP JAVA SOURCE SYS."Host";
    CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED SYS."Host" as import java.io.*;
    public class Host {
    public static void executeCommand(String command) {
    try {
    String[] finalCommand;
    if (isWindows()) {
    finalCommand = new String[4];
    // Use the appropriate path for your windows version.
    finalCommand[0] = "C:\\windows\\system32\\cmd.exe"; // Windows XP/2003
    //finalCommand[0] = "C:\\winnt\\system32\\cmd.exe"; // Windows NT/2000
    finalCommand[1] = "/y";
    finalCommand[2] = "/c";
    finalCommand[3] = command;
    else {
    finalCommand = new String[3];
    finalCommand[0] = "/bin/sh";
    finalCommand[1] = "-c";
    finalCommand[2] = command;
    final Process pr = Runtime.getRuntime().exec(finalCommand);
    pr.waitFor();
    new Thread(new Runnable(){
    public void run() {
    BufferedReader br_in = null;
    try {
    br_in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
    String buff = null;
    while ((buff = br_in.readLine()) != null) {
    System.out.println("Cmd results: " + buff);
    try {Thread.sleep(100); } catch(Exception e) {}
    br_in.close();
    catch (IOException ioe) {
    System.out.println("Exception caught printing process output.");
    ioe.printStackTrace();
    finally {
    try {
    br_in.close();
    } catch (Exception ex) {}
    }).start();
    new Thread(new Runnable(){
    public void run() {
    BufferedReader br_err = null;
    try {
    br_err = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
    String buff = null;
    while ((buff = br_err.readLine()) != null) {
    System.out.println("Cmd Error: " + buff);
    try {Thread.sleep(100); } catch(Exception e) {}
    br_err.close();
    catch (IOException ioe) {
    System.out.println("Exception caught printing process error.");
    ioe.printStackTrace();
    finally {
    try {
    br_err.close();
    } catch (Exception ex) {}
    }).start();
    catch (Exception ex) {
    System.out.println(ex.getLocalizedMessage());
    public static boolean isWindows() {
    if (System.getProperty("os.name").toLowerCase().indexOf("windows") != -1)
    return true;
    else
    return false;
    /

  • How to call another directory java program?

    Hi All,
    For Example:
    My program is here in two directories.Let Think that directory names like A and B.
    Let Program names like Aprog(A directory) and Bprog(B directory).
    I want to call Aprog to Bprog method.
    How to call?
    Plz., help me ASAP.
    --Mohan                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    My program is here in two directories.Let
    Think that directory names like A and B.
    It's more complicated than that. A java program consists of multiple .class files. In general you have one or more "trees" of directories of .class files, where the structure of the tree reflects the package structure. So a the class file for "org.dingbat.Thingy" is <basedir>/org/dingbat/Thingy.class where <basedir> is some directory on the class path.
    So referencing one class from another in different directories requires that the source provides the "fully qualified name" of the class (usually on an import) and making sure that, if it's in a different class file tree, both base directories are on the class path.

  • How to call  Screen in another program from exsisting program

    Hello Frieds,
    Can any one help me how to call  a screen  in another program (Say "test2") from exsisting program(say "test1')
    If above case is possible then how to access the fields in the target screen?
    Your responce is greatly appreciated.
    Best Regards,
    Rakesh

    Hi Rakesh,
    If you wish to use ONLY the screen of another program, call transaction  will not help you, because the called transaction will be fully executed (and not only the screen), and the acess to screen field wil be difficult.
    When you wish to access the same screen from more than one program, you can create this screen in a function module and in this way you can call the function (to display the screen) in many programs.
    Best regards,
    Leandro Mengue

  • How to call a set method from within a constructor

    Hello,
    I want to be able to call a set method from within a Scanner, to be used as the argument to pass to the Scanner (from a source file). Here's what i tried:
    private void openFiles()
            input = new Scanner( setSource );              
        and here is the set method:
    public String setSource( String in )
            source = in;
            return source;
        }obviously there will be more code in this method but i'm trying to tackle one problem at a time. Thanks in advance..

    The "String in" declaration says: "Nobody may ever invoke setSource() without specifying a certain String. The content of the String is known at run-time only."
    In no place in your code you say the compiler: "I want the 'in' variable (actually, parameter) of method setSource() to contain the first arg which is passed to the application".
    This is exactly the same mechanism allowing you to write "new Scanner" with something inside the two parentheses.

  • How to call a darwin command from c-code?

    Is there a way to call a Darwin command (in my case unzip )
    from a bundle written in c language?
    Thanks

    "man 3 system"
    system("unzip filename");

  • How to call operating system commands?

    Can we call OS commands from JAVA?
    I am trying to call lpr/lp commands from JAVA.
    Can anybody guide me where to search for this information.
    Thanks in advance
    Srini

    Thanks for you all for this information. I will try this....Your information greatly helped me to go forward...

  • How to call a Oracle Form from within the APEX

    Hi,
    I have a requirment where need to call a oracle form from within the Oracle APEX application?
    I will appriciate if can someone help me out.
    Thanks

    Hi,
    are you working with Forms 6i or 10g?
    If you want to call a forms 10g page. Just use a button with javascript:
    - Target type: URL
    - URL Target: javascript:window.open ('http://<server>:<port>/forms/frmservlet?config=<conf>','Forms window');
    With Forms 6i you can open the directory where your forms file is inside (works just with IE):
    <script type="text/javascript">
    function fnc_window()  {w = open('C:\\FormsFiles', "winLov","scrollbars=yes,resizable=no,width=600,height=400");
    if (w.opener == null)
    w.opener = self;
    </script>Or execute the forms file with vbscript (IE only):
    <script language = "vbscript">
    sub fnc_forms()
    dim progName
    progName = "c:\FormsFiles\myForm.exe"
    set oShell = createobject("wscript.shell") 'create a shell
    '***use the line below to call your app, defined above with the "progName" variable:
    oShell.run(progName)
    end sub
    </script>

  • How do I know HOST command status?

    Hi Guys,
    I am running a shell script at middle tier (on application server) from web forms using HOST command.
    My script may return TRUE or FALSE but executes successfully. Can I catch the True/False status of the script and see it in Forms?
    Is there any way to find the HOST command status?
    Thanks a lot
    ~Gouri Sankar

    Hi,
    can you write the value in a temporary file and read it from there ?
    Frank

Maybe you are looking for

  • Change the world, one VI at a time

    Are you passionate about LabVIEW, certified in LabVIEW development, active in the LabVIEW community, writing your own LabVIEW tools, and wishing that LabVIEW was even more powerful than it is today?  So are we, and we're looking for great people who

  • How do I get the statistics express to read more than 10 segments when reading from a .lvm

    I have tried 2 ways of doing this.  I had an for loop set up with a "Read labVIEW Measurement FIle" then a xy chart to plot the 2 measurements vs. each other.  The chart works and will plot everything great but the "Statistics" express will only take

  • Jive Forums default username and password

    i have installed 11.1.1.4 webcenter version, everything is running fine, but when i am trying to configure dicussions, i need to login http://*.*.*.*:8890/owc_discussions/admin for configuration, but i am not able to login with weblogic/weblogic1 Ple

  • Data binding with Multiple Filter

    Hi Experts, I am trying to do the data binding using filters with multiple values. ex: I am selecting the multiple values from list dialog and those i want to pass to odata service as a filters. name : abc                pqr I am looping on above and

  • Does opening your InDesign CC 2014 Hyperlink tab freeze the application?

    I have our company's 36-page catalog originally created in CS6 in December 2013, then opened and save in CC in May 2014 and then opened and saved in CC 2014 last week, that is giving me problems whenever I try and open the "Hyperlinks" tab window fro