Java running host command

Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
PL/SQL Release 11.1.0.6.0 - Production
CORE     11.1.0.6.0     Production
TNS for HPUX: Version 11.1.0.6.0 - Production
NLSRTL Version 11.1.0.6.0 - Production
Hi,
I am not familiar with Java setting in Oracle
I have a a stored procedure that call a java program to execute host command like
ssh user1@localhost '/home/user1/someprogram'
if we execute this directly using PuTTY
we can do the following with no problem
su - oracle
ssh user1@localhost '/home/user1/someprogram'
but when we execute the stored procedure,
we have to do
*/usr/bin/ssh* user1@localhost '/home/user1/someprogram'
does anybody where to set the path or environment to make the java know the path correctly.
thanks
Edited by: HGDBA on Mar 11, 2011 10:49 AM

OK. You can try the following:
Login as the Unix user (e.g. oracle) on the pre-upgrade environment and run the following command.
echo $PATH
Repeat the above in the post-upgrade environment and compare the two outputs. Generally, PATH will be set using an environment script called from .profile of the user or it could be directly defined in .profile.
You can check this by examining the .profile after logging in as the OS user (e.g. oracle):
vi ~/.profile #i.e check the .profile in the user's home directory.
It's my best guess, as sometimes the PATH could be added later on (for. e.g by another script). Anyways, give it a try and tell what you find.

Similar Messages

  • Java running host command - moved from PL/SQL forums

    Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
    PL/SQL Release 11.1.0.6.0 - Production
    CORE 11.1.0.6.0 Production
    TNS for HPUX: Version 11.1.0.6.0 - Production
    NLSRTL Version 11.1.0.6.0 - Production
    Hi,
    I am not familiar with Java setting in Oracle
    I have a a stored procedure that call a java program to execute host command like
    ssh user1@localhost '/home/user1/someprogram'
    if we execute this directly using PuTTY
    we can do the following with no problem
    su - oracle
    ssh user1@localhost '/home/user1/someprogram'
    but when we execute the stored procedure,
    we have to do
    */usr/bin/ssh* user1@localhost '/home/user1/someprogram'
    does anybody where to set the path or environment to make the java know the path correctly.
    thanks
    ps:. this is happen after we recently upgraded our Oracle from 9.2.0.8 to 11.1.0.6

    pgoel wrote:
    You said,
    a stored procedure that call a java program to execute host command like ssh user1@localhost '/home/user1/someprogram'SP -calls> Java Program (JP) -runs> ssh user1@localhost '/home/user1/someprogram'. is that right? I presume locahost is a database server.correct
    this is the stored procedure
    CREATE OR REPLACE PROCEDURE host_command (p_command  IN  VARCHAR2)
      AS LANGUAGE JAVA
      NAME 'Host.executeCommand (java.lang.String)';and this is the java
    create or replace and compile java source named 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("Process out :" + 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("Process err :" + 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;
    Where does Java Progarm reside? On the database server filesystem OR within the Database itslef. within the Database itslef.
    Edited by: HGDBA on Mar 11, 2011 1:50 PM

  • Not able to create Oracle External Procedure to Run Host Commands

    Trying to follow this article
    http://timarcher.com/node/9
    Its related to
    Oracle External Procedure to Run Host Commands
    steps
    1)mkdir –p /u01/app/usfapp/oracle_external_procs/oracle_host
    2)
    Author is suggesting to create a file
    but header file is missing in very first line... may be not sure..say it is <stdio.h>Create a file named oracle_host.c. The contents of this file will be:
    #include
    int RunCmd(char *cmd)
    return(system(cmd));
    4) Create the file named makefile. The contents of this file will be:
    oracle_host: oracle_host.o
    gcc -shared -o oracle_host.so oracle_host.o
    $ cat makefile
    oracle_host: oracle_host.o
         gcc -shared -o oracle_host.so oracle_host.o
    5)
    Now run the command make
    The output on my server looks like:
    [u01/app/usfapp/oracle_external_procs/oracle_host]
    banner@usfbannerte [TRNG] > make
    gcc -shared -o oracle_host.so oracle_host.o
    here I stuck .. Not able to run this step ]$ make
    gcc -shared -o oracle_host.so oracle_host.o
    /usr/bin/ld: oracle_host.o: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
    oracle_host.o: could not read symbols: Bad value
    collect2: ld returned 1 exit status
    make: *** [oracle_host] Error 1
    Any one has any idea what went wrong
    Any other link related to this is most welcomed.
    Please suggest ...

    hi
    please update
    or
    provide any other link / document for
    Oracle External Procedure to Run Host Commands
    --using c
    Thanks in advance.

  • Is it possible to run host command in sap environment

    hi
    could any body tel me
    is it possible to run host command in sap environment
    then how..?

    yeah , by using FM
    EXECUTE_FUNCTION
    Regards
    Prabhu

  • Is it possible to run host command from SAP environment? How do you run?

    Hi
    Is it possible to run host command from SAP environment? How do you run?
    Thank You

    Hello Subhash
    You will more details in the following thread:
    Re: How to define command for SXPG_COMMAND_EXECUTE
    Regards
      Uwe

  • Can PL/SQL Run Host Command (DOS Command) ??

    Hi All,
    Can PL/Sql run HOST Command ?
    If can't, iis there any other way to execute the DOS command ?
    Thanks for help.
    Iwan

    Hi sarah,
    i have tried, but it didn't work.
    in my abc.sql script : (host in pl/sql level)
    BEGIN
    HOST('cmd /C dir *.*');
    END;
    exit
    but it still didn't work
    so i tried in sqlplus level :
    variable vStatus VARCHAR2(1);
    variable vCmd VARCHAR2(3000);
    BEGIN
    :vCmd := 'C:\Program Files\Internet Explorer\iexplore';
    END;
    HOST("C:\Program Files\Internet Explorer\iexplore");
    EXIT;
    if i put HOST("C:\Program Files\Internet Explorer\iexplore"); --> it worked....
    If i put HOST(:vCmd); --> i won't work.
    Any body can help ?
    Thanks,
    Iwan

  • Possible to run host command ???

    Hi experts,
    Is it possible to run host command from SAP environment? How do you run? 
    Thanks,
    Logu

    check whether this helps
    DATA:os TYPE sxpgcolist-opsystem.
        DATA:host TYPE rfcdisplay-rfchost.
        DATA:commandname TYPE sxpgcolist-name.
        DATA:exec_protocol LIKE STANDARD TABLE OF btcxpm.
        os = sy-opsys.
        host = sy-host.
        commandname = 'ZDOWNLOAD'.  "SAP Command Name
        CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
          EXPORTING
            commandname     = commandname
            operatingsystem = os
            targetsystem    = host
            stdout          = 'X'
            stderr          = 'X'
            terminationwait = 'X'
          TABLES
            exec_protocol   = exec_protocol[].
        IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.

  • Wht is run host command.

    Is it possible to run host command from SAP environment? how do u run

    Hello Shilpa,
    Please check the prerequisites for calling external Programms where the Host calling is described in detail in this folllwog link.
    http://help.sap.com/saphelp_nw2004s/helpdata/en/c4/3a7fbb505211d189550000e829fbbd/content.htm
    Please award points for helkpful answers.
    Revert back for queries.
    Br,
    Sri

  • How java runs in command prompt and why java runs on it

    how java runs in command prompt and why java runs on it

    command prompt was used before the development of IDEs like RAD,eclipse etc.
    its still used for better understanding of the compilation and errors.
    type the java file and save the file(source file) in the bin folder of ur jdk environment with extension .java. the source file must be the one that has the main method declared.
    in the cmd prompt screen , set the path of bin folder.
    eg:C:/program files/jdk(some version)/bin/...
    for compilation,type:
    javac (source file_name).java and press enter
    for running the file:
    java source file_name

  • Trouble Running Host Command

    Hello folks I am trying to create a procedure to run linux host commands. I have found and used code available throughout the internet and it compiles and runs, but no matter what command I send to the host I get a 'Not Found' exception, even if I send as the command the full path to the executable. Here is my code:
    *1- Java Procedure*
    CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Host" AS
    import java.io.*;
    public class Host {
    public static void executeCommand(String command) {
    try {
    String[] finalCommand;
    if (System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) {
    finalCommand = new String[4];
    finalCommand[0] = "C:\\winnt\\system32\\cmd.exe";
    finalCommand[1] = "/y";
    finalCommand[2] = "/c";
    finalCommand[3] = command;
    } else {                              // Linux or Unix System
    finalCommand = new String[3];
    //finalCommand[0] = "/bin/sh";
    //finalCommand[1] = "-c";
    //finalCommand[2] = "'" + command + "'";
    finalCommand[0] = command;
    finalCommand[1] = "";
    finalCommand[2] = "";
    // Execute the command...
    final Process pr = Runtime.getRuntime().exec(finalCommand);
    // Capture output from STDOUT...
    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("stdout: " + buff);
    try {Thread.sleep(100); } catch(Exception e) {}
    br_in.close();
    } catch (IOException ioe) {
    System.out.println("Error printing process output.");
    ioe.printStackTrace();
    } finally {
    try {
    br_in.close();
    } catch (Exception ex) {}
    // Capture output from STDERR...
    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("stderr: " + buff);
    try {Thread.sleep(100); } catch(Exception e) {}
    br_err.close();
    } catch (IOException ioe) {
    System.out.println("Error printing execution errors.");
    ioe.printStackTrace();
    } finally {
    try {
    br_err.close();
    } catch (Exception ex) {}
    catch (Exception ex) {
    System.out.println("Exception: " + ex.getLocalizedMessage());
         ex.printStackTrace();
    *2- PL/SQL Package*
    CREATE OR REPLACE PACKAGE CIF_HOST_PKG IS
    PROCEDURE host (p_command IN VARCHAR2);
    END CIF_HOST_PKG;
    PROCEDURE host (p_command IN VARCHAR2)
    AS LANGUAGE JAVA
    NAME 'Host.executeCommand (java.lang.String)';
    END CIF_HOST_PKG;
    *3- Java Permission*
    EXEC Dbms_Java.Grant_Permission('CIF', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
    EXEC Dbms_Java.Grant_Permission('CIF', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');
    exec dbms_java.grant_permission( 'CIF', 'SYS:java.io.FilePermission', '/bin/sh', 'execute' );
    exec dbms_java.grant_permission( 'CIF', 'SYS:java.io.FilePermission', '/bin/ps', 'read , execute' );
    exec dbms_java.grant_permission( 'CIF', 'SYS:java.io.FilePermission', '/bin/ls', 'read , execute' );
    *4- Test Code*
    set serveroutput on size 1000000
    exec dbms_java.set_output(1000000)
    exec CIF_HOST_PKG.host('/bin/ls -l');
    *5- Test Output*
    anonymous block completed
    Exception: Exception during creation of the process: java.io.IOException: '/bin/ls -l' not found
    java.io.IOException: Exception during creation of the process: java.io.IOException: '/bin/ls -l' not found
         at java.lang.OracleProcess.start(OracleProcess.java:259)
         at java.lang.ProcessBuilder.start(ProcessBuilder.java:483)
         at java.lang.Runtime.exec(Runtime.java:591)
         at java.lang.Runtime.exec(Runtime.java:464)
         at Host.executeCommand(Host:24)
    Any idea on what am I doing wrong?
    Thank you in advance,
    Andre

    Has oracle user permissions to /bin/ls ?
    try in sqlplus:
    host /bin/ls -lIf not try chmod 777 /bin/lsElse you can try my package http://github.com/xtender/xt_svn
    select * from table(XT_SVN_TEST.shell_exec('/bin/ls -l /var/tmp'))Best regards,
    Malakshinov Sayan

  • About running host command

    Hi,
    Suppose that I need to run 'zip' in the mean time when running Java, what should I use for calling such host command from O/S?
    Thks & Bst Rgds,
    Huamin

    Runtime.exec()

  • Run Host Command on UNIX

    Hi,
    We use JAVA source in Oracle to execute some unix commands directly from within stored procedures in Oracle.
    Our Java source looks like this :
    CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "HOST" AS
    import java.lang.*;
    import java.io.*;
    public class Host
    public static void executeCommand (String command, String etype) throws IOException
    String[] wFullCommand = {"C:\\winnt\\system32\\cmd.exe", "/y", "/c", command};
    String[] uFullCommand = {"/bin/sh", "-c", command};
    if (etype.toUpperCase().equals("W"))
    Runtime.getRuntime().exec(wFullCommand);
    else if(etype.toUpperCase().equals("U+"))
    Runtime.getRuntime().exec(uFullCommand);
    else if(etype.toUpperCase().equals("U"))
    Runtime.getRuntime().exec(command);
    CREATE OR REPLACE PROCEDURE Host_Command (p_command IN VARCHAR2, p_etype IN VARCHAR2)
    AS LANGUAGE JAVA
    NAME 'Host.executeCommand (java.lang.String, java.lang.String)';
    We call one unix shell script and discover that some UNIX commands from this shell script are executed and others not. A cp & touch command don't give problems whilst cat & unix2dos commands don't function.
    Can anybody help me on this subject?
    Thanks !
    Kris

    Hi Avi, thanks for your reaction. Got it to work with the unix scripts, the problem was a syntax error in the script itself.
    However I don't get it to function when I try to run a unix command directly. Normally the parameter U+ should decide to start it in a shell for scripts and otherwise it should run the command directly. (whithout the /bin/sh in front of it).
    I already adapted my source to try to execute the command in a new shell but without success :
    String[] uFullCommand = {"/bin/sh", "-c", "\'cp /export/home/caluwaek/test/bestand2 /export/home/caluwaek/test/bestand8\'"};
    I tried to put the whole command in one string, in 3 strings, to just call the cp command without bothering the shell. Nothing seems to work.
    In unix both the following work :
    cp /export/home/caluwaek/test/bestand2 /export/home/caluwaek/test/bestand8
    and
    /bin/sh -c 'cp /export/home/caluwaek/test/bestand2 /export/home/caluwaek/test/bestand8'
    Thanks for your help!
    Kris

  • HOST command not working in forms 10g

    Hi,
    I have migrated forms 6i to forms 10g, and having a requirement to open sqlplus prompt using a form menu. I have used the below command: -
    "host('sqlplus '||user_name||'/'||pass||'@'||sid, no_screen);"
    But I am not able to get the sqlplus window, and the main form is still in process for long time, till i bounce the server.
    The forms are deployed on Oracle Applications Server 10g and i want to run it on server side.
    Please help me with the problem.
    Thanks,
    Ankit

    The deployment architecture is different between forms 10g and forms 6i.
    In Forms 6i HOST built-in command will run on the client machine since you are running as client/server, but in WebForms (Forms10g) the HOST built-in command will run on the middle tier which is your application server machine.
    In order to run hosts commands in WebForms you need to use webutil and use CLIENT_HOST in the webutil.
    check the [Forms 10g R2 Demo|http://download.oracle.com/otndocs/demos/Forms_Demos_10gr2.zip] for sample codes of webutil.
    You are using NO_SCREEN in your example, this will hide the window.
    Tony
    Edited by: Tony Garabedian on Nov 26, 2009 2:43 PM

  • Use Host command in Oracle Database Trigger

    I need to run Host command from a database trigger in order to execute a sh file in a Solaris, Unix, environment. How can I do it? The database environment is in Solaris and the database is 10g.
    Please let me know as soon as possible.

    Hi,
    read this <http://devtrigger.blogspot.com.br/2012/08/svn-backup-on-unix-or-solaris.html>
    Or
    you can to run in nohup. For example
    You can a script with the command vi about your trigger and run with the sintaxe bellow:
    nohup sqlplus "/as sysdba" @script.sql &
    Where "script.sql" is the name of the your file.
    Kind regards,
    Bruno Reis.
    www.brunors.com

  • 10g Forms Demo - Client side host command Jar file.

    Hi all,
    In the ORACLE 10g forms demo , client side host command jar is missing , atleast for me.
    Is that available at any link?
    Or anyone having it..?
    Please give me a clue..
    Or mail me, please([email protected])
    Thanks
    Jeneesh

    The deployment architecture is different between forms 10g and forms 6i.
    In Forms 6i HOST built-in command will run on the client machine since you are running as client/server, but in WebForms (Forms10g) the HOST built-in command will run on the middle tier which is your application server machine.
    In order to run hosts commands in WebForms you need to use webutil and use CLIENT_HOST in the webutil.
    check the [Forms 10g R2 Demo|http://download.oracle.com/otndocs/demos/Forms_Demos_10gr2.zip] for sample codes of webutil.
    You are using NO_SCREEN in your example, this will hide the window.
    Tony
    Edited by: Tony Garabedian on Nov 26, 2009 2:43 PM

Maybe you are looking for