OS Commands not executing through published java procedure... :(

Hello all :)
Im trying to get a PL/SQL block to delete a file out in the OS. Theres plenty of examples out there and the one I got came from burleson consulting, and incorporates a java method and a call to java wrapped in PL/SQL.. after all suggested grants, using the procedure yields no result. Here is the source code
-- java procedure used to execute OS command
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];
finalCommand[0] = "C:\\WINDOWS\\system32\\cmd.exe";
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);
new Thread(new Runnable() {
public void run() {
try {
BufferedReader br_in = new BufferedReader(new
InputStreamReader(pr.getInputStream()));
String buff = null;
while ((buff = br_in.readLine()) != null) {
System.out.println(buff);
try {Thread.sleep(100); } catch(Exception e) {}
br_in.close();
catch (IOException ioe) {
System.out.println("Exception caught printing process output.");
ioe.printStackTrace();
}).start();
new Thread(new Runnable() {
public void run() {
try {
BufferedReader br_err = new BufferedReader(new
InputStreamReader(pr.getErrorStream()));
String buff = null;
while ((buff = br_err.readLine()) != null) {
System.out.println(buff);
try {Thread.sleep(100); } catch(Exception e) {}
br_err.close();
catch (IOException ioe) {
System.out.println("Exception caught printing process error.");
ioe.printStackTrace();
}).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;
-- PL/SQL wrapper to publish java method.
CREATE OR REPLACE PROCEDURE host_command (p_command IN VARCHAR2)
AS LANGUAGE JAVA
NAME 'Host.executeCommand (java.lang.String)';
these are the grants I am issuing on install:
BEGIN
DBMS_JAVA.grant_permission ('LOANADMIN', 'java.io.FilePermission',
'<>', 'read ,write, execute, delete');
DBMS_JAVA.grant_permission ('LOANADMIN', 'SYS:java.lang.RuntimePermission',
'writeFileDescriptor', '');
DBMS_JAVA.grant_permission ('LOANADMIN', 'SYS:java.lang.RuntimePermission',
'readFileDescriptor', '');
END;
-- and this is the block I am using to execute the OS command..
1 BEGIN
2 host_command (p_command => 'DEL C:\PRETEND.TXT');
3* END;
SQL> /
PL/SQL procedure successfully completed.
Everything returns as successfully completed. But the file is not deleted from the server. I know im missing some kind of privilege. Can anyone help me? Thanks
Mo

Burleson consulting...
Says it all. Exposure on the Net doesn't mean quality.
Burleson code usually has not been tested, is not robust, and quite often doesn't work.
Why didn't you implement run_cmd, as suggested earlier?
THAT works!
Sybrand Bakker
Senior Oracle DBA

Similar Messages

  • Xml file not generated through Pl/sql procedure as a concurrent executable

    Hi,
    I getting error while genarating xml file through Pl/sql procedure as a concurrent executable file.
    Error Message:
    The XML page cannot be displayed
    Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
    Invalid at the top level of the document. Error processing resource

    Hi,
    Make sure the file has the XML header:
    <?xml version="1.0" encoding="UTF-8"?>
    or similar.
    Regards,
    Gareth
    Blog: http://garethroberts.blogspot.com/

  • End-of-communication channel while executing sqlldr from java procedure

    Hi all,
    I am having 10g 10.1.0.3.1 ( Infrastructure ) on linux, I am executing Sql Loader
    ( sqlldr ) from client (XP) using java stored procedure. After loading the data I am getting Error - ( end-of-communication channel). But same java procedure is working fine without any error on 10g without (Infrastructure). Is this problem is becuase of infrastructure or some patch has to be installed on the database. For my satisfaction I reinstalled java Virtual Machine on database with the help of
    ( initjvm.sql ). But problem is still there. Any idea what exactly the problem is.
    SKM

    This is the most frequently asked question from Oracle developers.. Never mind putting some light on this error, I want to put it alight! ;-)
    First thing. It is not The Error. It is a sympton of an error.
    This message does not come from the database. It comes from the client OCI (of JDBC) drivers - which suddenly discovered that the Oracle connection (usually a TCP socket connection) has been torn down at the server side. It attempts to write to that socket, only to find that the other party has hung up.
    Why has the other party hung up? That party is either a Dedicated Server Process or a Dispatcher Process. If a dedicated server dies (crashes), it will take its socket handles with it to The Great Recycle Bin In The Sky. If you was serviced by a shared server and it died, the Dispatcher (who handles the TCP comms for it), will automatically close that shared server's connection.
    Usually when a process dies on the Oracle server, it leaves behind an error in the alert log, and trace files. That is where you will find the inklings of what The Error was that caused your client to get the EOF on comms channel message.

  • Job not executing through database link

    hello all,
    we have a database server with oracle 10g enterprise edition on RHEL 5.3 64-bit , we have created a procedure which pulls data from a remote server using a procedure. that procedure collect data in cursor ..both server are connected using RF connectivity..
    but after every 2 or 3 days i saw that data is not pulled and job is marked as broken .... and when i mark that job as unbroken and try to rexecute that procedure it hangs for long.....
    i don't understand whats going on....i have also seen large number of sessions in my database..is possible that huge number of session are consuming resources and that's why oracle is unable to execute the job??? i have check network also but it is fine...i can access that remote server using VNC or team viewer..so network is definitely not an issue...
    i also set SQLNET.EXPIRE_TIME=10 in sqlnet.ora file and also created a profile for idle_time to get rid of excess inactive sessions....what might be issue??? any suggestion is appreciable...
    thanks and regards
    VD

    hello sir,
    actually it is not about the job, i am sure that procedure is causing problem..... because when i try to execute that procedure , it also hangs, i check all requirements need to be checked..... i think lots of inactive sessions causing this issue, but even after adding sqlnet and profile i is not removing those sesions and hence i think that procedure is not executing....
    coz the database i am connecting is having already connections and doing lots of transactions...so i it possible that it might be an issue.??
    sometime i also got timeout error while connection to that remote server but it is not issue because at the same time i am connected to it from another machine..
    thanks and regards
    VD

  • Running Shell Commands (not Executable) in Unix from Java

    What are my options to run shell commands from Java?
    My goal is to change my existing shell environment variables to some new ones provided by .anotherProfile.
    Using an executable from Java is not an option because it does not work i.e. ( exec(". /home/.profile") ) brings up errors.
    Someone has suggested that I start a child shell with that profile and work from there, but I'm unfamiliar with that sort of syntax and programming in general.
    Any good help equals duke dollars :)

    Well there are some possibilities. In the original thread you mentioned that you wanted the shell script to be executed to change some enviroment parameters of the shell the JVM is executing in.
    If so, and you are able to rewrite the profile so you can parse it manually. Then you can change some environment setting by writing the JNI wrappers for the getenv and setenv system calls. (Check your man pages)
    That will change the environment. I am just wondering what good it will do for you? What's use of sourcing the profile in a JVM?

  • Jar command not execute !

    Hello!
    I have jdk6u35 (64-bit) alongwith Weblogic1036 and 11gr2 Forms/Reports (64-bit).
    When I give following command to make a jar file for icons;
    jar -cvf frmicons.jar *.gif
    It doesn't execute, as it is not recognised as an internal command or external command.
    Guide me please.
    Thanks with Regards.
    Bhatt.
    Edited by: 982164 on Mar 31, 2013 1:38 PM

    Hi Bhatt,
    You need to add your java to your path.
    I think you are using windows so just add the path to bin folder from java to PATH variable and you will be able to execute the command.
    For example if you have java installed in C:\Program Files\Java\jdk1.6.0_37 just add the following to PATH environment variable at the beginning:
    C:\Program Files\Java\jdk1.6.0_37\bin; You may follow this guide:
    http://www.kingluddite.com/tools/how-do-i-add-java-to-my-windows-path
    Hope this helps you :)
    Regards
    Carlos

  • Host command not executing Excel File

    Hi,
    I am trying to open a Excel file through a bat file.
    And calling this bat file from Oracle Forms 10g - Forms [32 Bit] Version 9.0.4.0.19 (Production).
    But some how nothing is happening.
    But if I issue - host("echo hello > c:\hello.txt"); --> this works fine.
    Host command is as - host('cmd.exe /c c:\temp_dir\File_test.bat');
    and the bat file contains following lines -
    File_test.bat
    cd c:\temp_dir
    PATH c:\Program Files\Microsoft Office\Office11\
    EXCEL Book2.xls
    Can anyone please provide some guidance in this regard?
    Thanks in advance!
    Avinash.
    Pune- India.

    Hey Guys,
    Thanks for your replies,
    But it seems I couldn't communicate my point to you.
    I want to execute the command on application server and not on client machine.
    I guess by using WEBUTIL_HOST it will execute the the command on client side and not on application server.
    I hope i made my point clear.
    Thanks for your help, looking forward to get more help!
    Thanks again!
    Avinash.
    Pune - India.

  • Can not insert through dblink in procedure

    I have created one procedure which is selecting,inserting and updating data to another database on same server using dblink. it select and update data successfully but when it is going to insert using dblink it gives following error.
    ORA-02019: connection description FOR remote DATABASE NOT FOUND
    ORA-02063: preceding line FROM PAS
    But when i executed same insert statement on sql prompt it is exeuted successfully.
    insert into tab1@dblink values('blah','blah','blah');
    I have dropped all my dblink and recreate it again i have given priveleges externally means insert any table,select any table,update any table to username.
    but still i have recieved same error. Please guide me.
    Global name of database is same as dblink name.
    Thanks in advance
    dhaval

    1. select * from global_name
    PAS and RATEPAS
    I have created two database on same server.
    named pas and ratepas.
    I can not send procedure's code. but actual logic of procedure is selecting a record from temporary table and check whether it is a valid record on the basis of time_stamp and it is inserting a record to base table and update time_stamp to other two tables. and it is giving error only when
    SELECT * FROM dba_db_links;
    OWNER
    DB_LINK
    USERNAME
    HOST
    CREATED
    PUBLIC
    PAS
    PASUSER
    OWNER
    DB_LINK
    USERNAME
    HOST
    CREATED
    pas125
    13-OCT-05

  • Maxl shell command not executing

    I'm running Essbase from a Solaris environment. I have a MAXL script that exports an Essbase database, shuts down Essbase, and issues shell commands to copy the Analytic Services directories to backup directories. The script was running without problems until a Solaris patch, generic patch 127111-09, was installed. Since then the shell commands are no longer executing. Does anyone know why these shell commands are no longer executing.
    Thanks,
    Tom

    Already checked, no change in the permissions. There was a bug, see link, when doing a recursive remove that was corrected. Not sure if this is related.
    Link: [http://bugs.opensolaris.org/bugdatabase/view_bug.do;jsessionid=fa9dddbcb3ede12a9d5b4a397cef?bug_id=4677347]
    Thanks,
    Tom

  • PSFTP mput command not executing.

    Hello Guys,
    In my below mentioned script, everything is working fine, I'm able to push file on server through put command. But when I'm using mput command to upload multiple files script stucks with no output. I did lot of research but no success. Could anyone of you
    can tell me where exact issue is ?
    strHostname = "transfer.com"
    strUsername = "User1"
    strPassword = "password"
    strLocalDir = "C:\data"
    strRemoteDir = "Sales"
    PSFTP_DIR = "c:\windows\"
    PSFTP_EXE = PUTTY_DIR & "psftp.exe"
    strFile1="*.txt"
    'strGetFile ="abc.txt"
    strFtpScriptFile = "c:\myscript.txt"
    strOutputFile = "C:\output.txt"
    Set WshShell=CreateObject("Wscript.Shell")
    Set fso=CreateObject("Scripting.FileSystemObject")
    Set oFile=fso.OpenTextFile(strFtpScriptFile,2,true)
    oFile.WriteLine "lcd " & chr(34) & strLocalDir & chr(34)
    oFile.WriteLine "cd " & chr(34) & strRemoteDir & chr(34)
    oFile.WriteLine "ls" & chr(34)
    'oFile.WriteLine "get " & chr(34) & strGetFile & chr(34)
    File.WriteLine "mput " & strFile1
    oFile.WriteLine "quit" & chr(34) & vbCrLf 
    oFile.Close
    Set fso = Nothing 
    PSFTP = "C:\windows\psftp.exe -v -be -bc " & " -l " & strUsername & " -pw " & strPassword & " " & _
    strHostname & " -b " & strFtpScriptFile & " >> " & strOutputFile & " 2>&1"
    MsgBox PSFTP
    WshShell.Run PSFTP,1.True
    WScript.Echo oScriptExec.ExitCode
    Set oFile = Nothing
    'WScript.Echo oScriptExec.StdErr.AtEndOfStream
    WScript.Quit 
    Below is a output when I execute mput command.. 
    Looking up host "transfer.com"
    Connecting to <IP ADDRESS> port 22
    Server version: SSH-2.0-Internet Server SSHD
    Using SSH protocol version 2
    We claim version: SSH-2.0-PuTTY_Release_0.63
    Doing Diffie-Hellman group exchange
    Doing Diffie-Hellman key exchange with hash SHA-1
    Host key fingerprint is:
    ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx
    Initialised AES-256 SDCTR client->server encryption
    Initialised HMAC-SHA1 client->server MAC algorithm
    Initialised AES-256 SDCTR server->client encryption
    Initialised HMAC-SHA1 server->client MAC algorithm
    Using username "User1".
    This is MFT KIILA QA env DMZ ServerAttempting keyboard-interactive authentication
    Access granted
    Opening session as main channel
    Opened main channel
    Started a shell/command
    PT

    mput command worked perfectly. As there was no indication of file uploading progress in %, I assumed script stucked in mid.
    Apart from question I asked I have few queries:
    1. As my log states above "Server version: SSH-2.0-Internet Server SSHD". I'm in need of codes list returned by
    server.
    2. Can it be possible to get file transfer rate means progress in %?
    3. Currently Which file is in use (means uploading). How can it be tracked?
    PT

  • Command not executed inside

    I've tried this, but i get no output. Why?
    while(tokenizer.nextToken()!= StreamTokenizer.TT_EOF)
                switch(tokenizer.ttype)
                    case StreamTokenizer.TT_EOL:               
                    break;
                    case StreamTokenizer.TT_NUMBER:
                    System.out.println(s.concat(Double.toString(tokenizer.nval)));
                    break;
                    case StreamTokenizer.TT_WORD:
                    System.out.println(s.concat(tokenizer.sval)); // Already a String
                    break;
                    default: // single character in ttype
                    s = String.valueOf((char)tokenizer.ttype);
                }//switch end
            }I've also tried this and i get output, but the the concat command has not any effect; the characters are printed one on each line.
    while(tokenizer.nextToken()!= StreamTokenizer.TT_EOF)
                switch(tokenizer.ttype)
                    case StreamTokenizer.TT_EOL:               
                    break;
                    case StreamTokenizer.TT_NUMBER:
                    s.concat(Double.toString(tokenizer.nval));
                    break;
                    case StreamTokenizer.TT_WORD:
                    s.concat(tokenizer.sval); // Already a String
                    break;
                    default: // single character in ttype
                    s = String.valueOf((char)tokenizer.ttype);
                }//switch end
                System.out.print(s);
            }Why? Is there any secret inside "switch"?

    I've also tried this and i get output, but the the concat command has
    not any effect; the characters are printed one on each line.Strings are immutable, so instead of this:s.concat(Double.toString(tokenizer.nval));do this:s= s.concat(Double.toString(tokenizer.nval));(the same applies to the other 'concat' statements).
    kind regards,
    Jos

  • We are trying to implement a process so that any document that needs to be printed through our Java application will be printed as PDF using Adobe Reader. For which, We created and execute the below command line to call Adobe Reader and print the PDF on a

    We are trying to implement a process so that any document that needs to be printed through our Java application will be printed as PDF using Adobe Reader. For which, We created and execute the below command line to call Adobe Reader and print the PDF on a printer."C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe" /T "\\<Application Server>\Report\<TEST.PDF>" "<Printer Name>". Current Situation: The above command line parameter when executed is working as expected in a User's Workspace. When executed in a command line on the Application Server is working as expected. But, the same is not working while executing it from Deployed environment.Software being used: 1. Adobe 11.0 enterprise version. 2. Webshpere Application Server 8.5.5.2. Please let us know if there is a way to enable trace logs in Adobe Reader to further diagnose this issue.

    This is the Acrobat.com forum.  Your question will have a much better chance being addressed in the Acrobat SDK forum.

  • Delete command are not executed in function of Java Bean

    Hello Sir,
    In Java bean have a function submitData.I want in this function run delete command through PreparedStatement..But Its not executed.
    Please review..
    public void submitData()
         try
    System.out.println("Printed*************************************************************");
    Class.forName("oracle.jdbc.driver.OracleDriver");
    System.out.println("Loading....");
    Connection con=DriverManager.getConnection("jdbc:oracle:thin:@VijayKumar-PC:1521:XE","SYSTEM","SYSTEM");
    System.out.println("Connection created");
    PreparedStatement st=con.prepareStatement("delete  from simple where NAME='?' and BNAME='?' ");
    String User=getUserName();
    st.setString(1,User);
    String Bname=getBookName();
    st.setString(2,Bname);
    int y= st.executeUpdate();
    System.out.println(y);
    System.out.println("Query Executed");
    con.commit();
    con.close();
    System.out.println("Your Book are Submitted *****************");
    catch(Exception e)
    e.printStackTrace();
    }Thanks.

    Dear Sir,
    I removed the singleaquotes from preparedstatement.But Its not executed in this function.Like:
    public void submitData()
         try
    System.out.println("Printed*************************************************************");
    Class.forName("oracle.jdbc.driver.OracleDriver");
    System.out.println("Loading....");
    Connection con=DriverManager.getConnection("jdbc:oracle:thin:@VijayKumar-PC:1521:XE","SYSTEM","SYSTEM");
    System.out.println("Connection created");
    PreparedStatement st=con.prepareStatement("delete  from simple where NAME=? and BNAME=? ");
    String User=getUserName();
    st.setString(1,User);
    String Bname=getBookName();
    st.setString(2,Bname);
    int y= st.executeUpdate();
    System.out.println(y);
    System.out.println("Query Executed");
    con.commit();
    con.close();
    System.out.println("Your Book are Submitted *****************");
    catch(Exception e)
    e.printStackTrace();
    }Allthough Insert command is properly executed in another function of Java Bean.
    Please review...
    Thanks.

  • Java App connection to an Oracle Database through Oracle Stored Procedure

    My team's access to its Databases (Oracle only) is restricted to access through Oracle Stored Procedures that are part of the Oracle Database. So, in my Java App I need to call the Stored Procedure that will give me the access to the table that I need, declare the right parameters and execute the command. The Stored Procedure will then hand me the data I need.
    I am finding support on the web for creating Stored Procedures in Java, but that is not what I need.
    Can anyone post here a class that addresses this, or point me to a link that will shed some light on it?
    Thanks
    user606303

    user606303 wrote:
    Sorry this code is unformatted - I can't see how to format it.Use \ tags
    I am looking for Java code that will do what this .NET code below does (connects to a database and writes data to the table through an Oracle stored procedure that is part of the Oracle Database.)
    So learn Java, learn JDBC and translate the requirements; don't attempt to translate the code as the platforms are too different.
    From a quick glance it looks like a JDBC CallableStatement can do the job.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Runtime.exec not executing the command !

    Hi all,
    I'm connecting to Progress Db thru JDBC trying to execute a stored procedure
    which has a statement
    Runtime.exec("ksh -c aa") where aa is aunix script which i'm trying to run from java snippet .
    when i run this code as a seperate java program it executes the script
    "aa" but thru JDBC connection it does not execute the command
    what could be the reason ???
    thanx in advance,
    Nagu.

    Hi Rick,
    "aa" is the shell script which is lying in the user DIR .
    It is returning a non-zero value. what kind of permissions be there for to execute the Shell command?
    Regards,
    Nagarathna.

Maybe you are looking for

  • File Menu Suddenly Slow

    Hello there about 3 weeks ago i noticed that my file menu has become extremely slow.... basically if you have a timeline or preview window selected and click file it lags for  4 - 5 seconds same deal with the 'export' menu.... i know there is another

  • Password change won't work outside webmail?

    Hi all, I changed my email password about 4 hours ago because I suspected I had typed my data into a phishing scam (luckily I realised within about 30 seconds what I had done, so I immediately went to the main BT site and changed my password from the

  • Macbook 13 Retina keyboard backlight not turning on

    Hi all, I've had my 13inch MPRr for about two weeks now and whenever it comes out of sleep from a LidOpen the keyboard backlight will seldom turn on.  It is pretty inconsistent but I can usually get it activated again when I put it into sleep manuall

  • User Exit on Fiscal Period

    Hi all, I have the following problem: I have a query where I need to compute the beginning of week and end of week values for certain key figures. Now I need to this analysis over a period of two fiscal years and also this analysis needs to be per fi

  • I can't access the iTunes store on my newly build Windows 8 computer

    I can't access the iTunes store from my computer. When I try it just hangs up with the "busy bar" are the top working away. I can download my stuff on my iPad or my iPod, but I do prefer using iTunes on my computer. I do have a Windows 7 machine, but