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';
/

Similar Messages

  • 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.

  • How to execute Linux command from Java app.

    Hi all,
    Could anyone show me how to execute Linux command from Java app. For example, I have the need to execute the "ls" command from my Java app (which is running on the Linux machine), how should I write the codes?
    Thanks a lot,

    You can use "built-in" shell commands, you just need to invoke the shell and tell it to run the command. See the -c switch in the man page for your shell. But, "ls" isn't built-in anyays.
    If you use exec, you will want to set the directory with the dir argument to exec, or add it to the command or cmdarray. See the API for the variants of java.lang.Runtime.exec(). (If you're invoking it repeatedly, you can most likely modify a cmdarray more efficiently than having exec() decompose your command).
    You will also definitely want to save the returned Process and read the output from it (possibly stderr too and get an exit status). See API for java.lang.Process. Here's an example
    java.io.BufferedReader br =
    new java.io.BufferedReader(new java.io.InputStreamReader(
    Runtime.getRuntime().exec ("/sbin/ifconfig ppp0").
    getInputStream()));
    while ((s = br.readLine()) != null) {...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Execute linux command from java

    I wanna execute linux command from java, bu the output has error:
    Return code = 1
    top: failed tty get
    The code as:
    import java.io.*;
    public class Execute {
         public static void main(String[] args) {
              try {
                   final Process process = Runtime.getRuntime().exec("top");
                   new Thread() {
                        public void run() {
                             try {
                                  InputStream is = process.getInputStream();
                                  byte[] buffer = new byte[1024];
                                  for (int count = 0; (count = is.read(buffer)) >= 0;) {
                                       System.out.write(buffer, 0, count);
                             } catch (Exception e) {
                                  e.printStackTrace();
                   }.start();
                   new Thread() {
                        public void run() {
                             try {
                                  InputStream is = process.getErrorStream();
                                  byte[] buffer = new byte[1024];
                                  for (int count = 0; (count = is.read(buffer)) >= 0;) {
                                       System.err.write(buffer, 0, count);
                             } catch (Exception e) {
                                  e.printStackTrace();
                   }.start();
                   int returnCode = process.waitFor();
                   System.out.println("Return code = " + returnCode);
              } catch (Exception e) {
                   e.printStackTrace();
    }Help please.

    Your code is probably good to run a program, that does not use terminal capabilities.
    Program "top" is a little bit more complicated - you have to run it with a real terminal.
    Try to run "xterm -e top". You can find an example how to run an external program
    from java code in cnd/gdb module on http://cnd.netbeans.org
    For example, take a look at openExternalProgramIOWindow() method on this page:
    http://cnd.netbeans.org/source/browse/cnd/gdb/src/org/netbeans/modules/cnd/debugger/gdb/proxy/Attic/GdbProxyCL.java?rev=1.1.2.6.2.5&only_with_tag=release551_fixes&view=markup
    It runs a command with external terminal.
    Thanks,
    Nik

  • Unable to execute Linux command from Java

    Hi,
    I am currently working on a code wherein i need to execute Linux command from Java. Below are some of the query i have.
    1) Is there any efficient method of running OS commands from Java, rather than using Runtime and Process method.
    2) Below is details of my code which fails in execution
    **-- Java Version**
    java version "1.6.0"
    OpenJDK Runtime Environment (build 1.6.0-b09)
    OpenJDK Server VM (build 1.6.0-b09, mixed mode)
    -- Program Code ----
    Where <path> = Path i put myself
    package test;
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileReader;
    import java.io.*;
    public class GetInode{
         * @param args
         public static void main(String[] args) {
              GetInode test = new GetInode();
              test.getInode();
         public void getInode(){                    
              String command = "/usr/bin/stat -Lt <path>;
              System.out.println(command);
              Process process;
              Runtime rt;     
              try{
              rt = Runtime.getRuntime();               
              process = rt.exec(command);
              InputStreamReader isr = new InputStreamReader(process.getErrorStream());
              BufferedReader bre = new BufferedReader(isr);
              BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream());
              System.out.println(bre.readLine());
    System.out.println(br.readLine().split(" ")[7]);
              process.destroy();          
              }catch (Exception ex){
                   System.out.println("Error :- " + ex.getMessage());
    ------Output -------------
    /usr/bin/stat -Lt "<path>"
    /usr/bin/stat: cannot stat `"<path>"': No such file or directory
    Error :- null
    Can any one help me what is wrong and why i am unable to run the Linux command from Java.

    For clarity purpose............i m submitting actual code here
    --- Code ---
    package test;
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileReader;
    import java.io.*;
    public class GetInode{
    * @param args
    public static void main(String[] args) {
    GetInode test = new GetInode();
    test.getInode();
    public void getInode(){               
    String command = "/usr/bin/stat -Lt \"/afs/inf.ed.ac.uk/user/s08/s0898671/workspace/CASWESBLIN/TestFS/01_FIL_01.txt.txt\"";
    System.out.println(command);
    Process process;
    Runtime rt;
    try{
    rt = Runtime.getRuntime();
    process = rt.exec(command);
    InputStreamReader isr = new InputStreamReader(process.getErrorStream());
    BufferedReader bre = new BufferedReader(isr);
    BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
    System.out.println(bre.readLine());
    System.out.println(br.readLine().split(" ")[7]);
    process.destroy();
    }catch (Exception ex){
    System.out.println("Error :- " + ex.getMessage());
    --- Output ---
    [ratz]s0898671: java GetInode
    /usr/bin/stat -Lt "/afs/inf.ed.ac.uk/user/s08/s0898671/workspace/CASWESBLIN/TestFS/01_FIL_01.txt.txt"
    /usr/bin/stat: cannot stat `"/afs/inf.ed.ac.uk/user/s08/s0898671/workspace/CASWESBLIN/TestFS/01_FIL_01.txt.txt"': No such file or directory
    Error :- null
    -- Linux Terminal --
    If i copy the first line from the output and execute on Linux terminal her is the output that i get
    [ratz]s0898671: /usr/bin/stat -Lt "/afs/inf.ed.ac.uk/user/s08/s0898671/workspace/CASWESBLIN/TestFS/01_FIL_01.txt.txt"
    /afs/inf.ed.ac.uk/user/s08/s0898671/workspace/CASWESBLIN/TestFS/01_FIL_01.txt.txt 12003 24 81a4 453166 10000 1c 360466554 2 0 1 1246638450 1246638450 1246638450 4096
    Can you just assist me where am i really making mistake.......i was wondering if the command that i pass from Java....can be executed on Linux terminal why is it faling to run from java.........and when i print the Error Stream for process output........it show cannot Stat.......

  • Problem in executing Linux command from Java Programme.

    hi everybody,
    can anybody help me to solve one problem i have.
    i want to capture the output of linux command "grep" in my java programme.but it is not working properly .(maybe this sub-process doesn't have permission to read files)
    here is my code and corresponding outputs.
    import java.io.*;
    public class BSearch
    public static void main(String kj[])
    try
    Runtime rt=Runtime.getRuntime();
    String command="grep \"hello\" -r /usr/MyDir ";               
    Process rtProc=rt.exec(command);          
    InputStream is=rtProc.getInputStream();
    BufferedReader br =new BufferedReader(new InputStreamReader(is));     
    String line =null;
    while((line=br.readLine()) != null)
    System.out.println(br.readLine());
    br.close();
    catch(Exception e)
    System.err.println("Error in command "+e);               
    it finds "hello" pattern only in BSearch.class file although if i fire this command on LINUX prompt it
    shows all the files in /usr/MyDir which contain "hello" pattern.
    java programme output :
    Binary file /usr/MyDir/BSearch.class matches.
    linux command output :
    /usr/MyDir/one.txt: hello sdfs
    Binary file /usr/MyDir/BSearch.class matches.
    /usr/MyDir/two.txt: kjsdf hello sdfsdf
    will anybody help me solve this problem.

    It may be a Problem of Catching the Echoes back from the Processes...I have a Program which Captures the Echoes..see if it works
    import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.beans.PropertyChangeSupport;import java.lang.ref.WeakReference;/** * Implements a proxy property change listener using a weak reference to avoid memory locking that would occur if it * was a strong reference. To understand this, we hve to understand that the property change listeners themselves are * hilding onto panels and other objects with strong java references. If the panel goes away while we are viewing an * object, we have a circular emory hold situation where the panel cant be collected because it has ahold of the * property and the property cannot because it has ahold of the pane. If we use weak references instead, then the hard * link between the listener and the producer is softened to almost nothing. */public class WeakPropertyChangeListener implements PropertyChangeListener {  /**   * A poperty change support object is included here so that the listener can remove   * himself from the listeners if the reference internally goes to null.   */  private PropertyChangeSupport pcs = null;  /** Holds the weak reference to the real listener. */  private WeakReference weakRef = null;  /**   * Constructs a new Proxy object for the given support and listener.   * @param pcs The property change support that this object will be using.   * @param pcl The real listener.   */  public WeakPropertyChangeListener(PropertyChangeSupport pcs, PropertyChangeListener pcl) {    if (pcs == null) throw new NullPointerException("pcs");    if (pcl == null) throw new NullPointerException("pcl");    this.pcs = pcs;    weakRef = new WeakReference(pcl);  } /** @see <{PropertyChangeListener}> */ public void propertyChange(PropertyChangeEvent changeEvent) {    Object referrant = weakRef.get();    if (referrant == null) {      pcs.removePropertyChangeListener(this);    } else {      ((PropertyChangeListener)referrant).propertyChange(changeEvent);    } } /** Returns true for comparison to referrant or this. */ public boolean equals(Object obj) {    if (obj instanceof WeakPropertyChangeListener) return super.equals(obj);    else if (obj != null)return obj.equals(weakRef.get());    else return false;  }}// snipet public void addPropertyChangeListener(PropertyChangeListener listener) {    this.propertyChangeSupport.addPropertyChangeListener(      new WeakPropertyChangeListener(this.propertyChangeSupport, listener));  } public void removePropertyChangeListener(PropertyChangeListener listener) {    this.propertyChangeSupport.removePropertyChangeListener(listener);  }

  • "send to color" command from FCP not working.

    Hello there...
    The problem i'm having is when I send to Color from FCP nothing happens.
    I'm working on a project all the footage is in DV... very straight forward.. i've worked with color in the past so i understand the process of preparing the material for Color.
    I restarted, created a new project, imported material in different codecs like pro res... and Nothing... Nada.
    I have the latest version of FCP and Color.
    i'm on a deadline so i want to avoid reinstall... any ideas??
    any help will be greatly appreciated!
    thanks!!!
    andres.

    Hello JP, Thanks for your reply!!
    Here are the answers...
    Restart: the application and computer (usually the solution to every problem in life)
    Created a new project In FCP.
    I'm not mixing any codecs... everything is straight edits no dissolves, no speed change, just cuts, all the material is the same source an old school mini DV camera 29.97fps.
    I'm trying to send a sequence form FCP. Actually the "send to color" command is highlighted.
    By nothing i mean:
    I select on file menu "Send to Color" command and I see the prompt window with the duration of the project (5min) Name of sequence... i change the name to v2... and thats it. Color doesn't open... I tryed opening color in advance and same thing. seems opening script is not working.
    Thanks for your reply and help!!!!!!
    best,
    Andrés.

  • Linux commands from java

    hi all,
    i ve to exectue linux commands in background from within the jsp /servlet/Ejb .what code lines should i write or any other procedure to execute those.
    i know u guys must ve done this before.
    tc

    If you was writing a standa alone Java application that runs top of J2SE, then you could use java.lang.Runtime.exec() apis to call an operating system command. But since you are writing a J2EE component, as per J2EE standard, you don't have the privileges to call Runtime.exec() api because that can lead to security hole. See section #6.2.3 of J2EE 1.4 platform spec (http://java.sun.com/j2ee/download.html#platformspec) for more details about security permission set available to a J2EE component.
    Sahoo

  • Calling Linux Command From Pl/SQL

    Hi!
    I need to create a trigger which will call a linux command. Basically, when a value changes in a table, I would like to run a linux script. The value in the table can change anytime during any day. I had a look at DBMS_JOB.SUBMIT but I'm not sure if this will work for me because I only need to run the linux script once - when the trigger is fired. I also don't wanna clutter the job queue. Please help. Thanx in advance.

    You didn't mention if you're looking for synchronous or asynchronous execution of your Linux command. Should the program wait for it to complete?
    If it has to be synchronous, you'll need to look into using the external program listener. If asynchronous is ok (and it usually is) and then I'd go with scheduling a job - don't worry about "cluttering up the job queue".
    If you're on 10g or later, don't bother with DBMS_JOB - use DBMS_SCHEDULER instead, which makes it much easier to execute an external process.

  • Invoke a linux command from with in a java servlet

    Hi Everyone,
    I am kind of new to Linux and Tomcat server technology. I have been trying to run a servlet that would run a linux command using the "Runtime.getRuntime().exec( cmd );" in java. I tried running the command in an independent Java Program and it runs fine. I am trying to do the same thing in a servlet so that I could invoke and execute the linux command when I invoke a servlet URL. But it does not seem to work. I mean the servlet program compiles well and prints all the html text but the command does not get executed. It does not give any error messages either. The program is as follws:
    public class Example1 extends HttpServlet {
    public void doGet(HttpServletRequest request,
    HttpServletResponse response)
    throws IOException, ServletException
    PrintWriter output;
         response.setContentType ("text/html");
         output = response.getWriter();
         StringBuffer buf = new StringBuffer();
         buf.append ("<html>");
         buf.append ("<head>");
         buf.append ("<title>\n");
         buf.append ("A Simple Servlet Example \n");
         buf.append ("</title>");
         buf.append ("</head>");
         buf.append ("<body>\n");
         buf.append ("Welcome to Servlets in SSL Command \n");
         buf.append ("</body>");
         buf.append ("</html>");
         System.out.println("Hello Linux");
         String cmd = "";
         cmd = "cp file1.txt file2.txt";
         System.out.println(cmd);
         try
              Runtime.getRuntime().exec( cmd );
         catch( java.io.IOException e )
              System.out.println("\n " + e.toString());
         output.println(buf.toString());
         output.close();
    do you have any suggestions reagarding this. Thx in Advance.
    Regards
    nsk

    Read this before you do anything with Runtime.exec:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    I agree with Annie: it's a bad idea to put code like this in a servlet. Move it into a JavaBean that you can test off-line and then let your serlvet simply instantiate it and call its methods.
    This will tie your app into Linux, of course. Sure you absolutely have to do this? Write an interface and a factory method to hide this implementation detail. It'll give you a chance to chance implementations if you ever have to deploy on Windoze or something else.
    Merry Christmas, Annie. Don't spend the day at the forum, as helpful as you are.

  • Exec a "MV" (move) Linux command from ABAP program using wildcard "*"

    Hi,
    I have a problem by using FM "SXPG_COMMAND_EXECUTE", SM49 while i try to move the whole content of a SAP folder into another.
    Foders are on the same file system:
    source: /tmp/
    dest:   /usr/sap/tmp
    I made a command in SM69 named ZMOVE:
    I put OS: Linux (is case sensitive)
            command: "mv"
            parameters: /tmp/* /usr/sap/tmp
    hence the final sentence should be "mv /tmp/* /usr/sap/tmp". I did it directly by using program "rsbdcos0" and works fine.
    Now if I try to execute the command ZMOVE from SM49 or using the function module it gives the same error
    *mv: cannot stat  /tmp/ ': No such file or directory**
    I made several tries by changing the parameter section (also using a script on the same directory).
    The permissions are ok, so the only problem seems to be the wildcard (*) character.
    Any suggestions?
    Thanks in advance
    Fabrizio

    Problem solved.
    Forget function modules, SM69 etc. there's an ABAP command in order to perform a SO command.
    Here an example:
    data: lf_file like rlgrap-filename,
          lf_idx(3) type n,
          cmd(254),
          result(255) occurs 100 with header line.
    cmd = 'mv /dir_source/* /dir_dest'.
      call 'SYSTEM' id 'COMMAND' field cmd
                    id 'TAB'     field result-sys.

  • Populating drop down menu's from database dynamically

    Hi
    I m facing a problem of populating the drop down menu from a MS Access database using JSP. But i m not able to do it. Can you please help me out?
    this works perfectly for textarea
    <textarea cols="20" rows="20">
    <% for(int i =1; i <=rsmd.getColumnCount();++i)
    out.println(rsmd.getColumnName(i)); %>
    </textarea>
    but for drop down box it gives problems
    Heres the code!
    <select name="aa" ID = "aa">
    <option value="<% for(int i =1; i <= rsmd.getColumnCount();++i)
    out.println(rsmd.getColumnName(i)); %>" > </option>
    </select>
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 61 in the jsp file: /gv/event.jsp
    Generated servlet error:
    i cannot be resolved
    wat can be the alternative? Please hlp
    Regards
    Sami

    Hi i m facing a problem in jsp while filling the dropdown box<select name="combosubject"  width="10%" maxlength="20"/>
                                  <option ></option>
                                  <%
                                                System.out.println("1st time");
                                                rs=stmt.executeQuery("select subject.name from subject order by name");
                                                while(rs.next())
                                                  subject = rs.getString(1);
                                             %>     
                                             <option ><%=subject%></option>
                                             <%
                             rs.close();
                             stmt.close();
                       %>the problem is that when i execute this code for the first time it works fine and after that it keeps on throwing exception like "No data found", "Column not found"
    on <form> action i have recalled this function that is when i click the search button this page is executed again and at this moment i got the exception

  • Can I send keyboard/mouse commands from a VI to an external application?

    I am launching an external application (BeamScan.exe by Photon) in Windows 95 from a LabVIEW 5.1 VI using Exec. I want to be able to configure the external application from its own menu bar, sending key commands or mouse clicks from the VI. I need to do it this way because the external application has only limited ActiveX capabilities which do not include the menu options I want to control.
    Is it possible to send keystrokes or mouse clicks through Windows 95 to the other application?

    Steve_rvk wrote:
    > I am launching an external application (BeamScan.exe by Photon) in
    > Windows 95 from a LabVIEW 5.1 VI using Exec. I want to be able to
    > configure the external application from its own menu bar, sending key
    > commands or mouse clicks from the VI. I need to do it this way
    > because the external application has only limited ActiveX capabilities
    > which do not include the menu options I want to control.
    >
    > Is it possible to send keystrokes or mouse clicks through Windows 95
    > to the other application?
    Download "Simulate Click" and "Simulate Key Event" from my web site.
    It's on G Toolbox page.
    George Zou
    http://gtoolbox.yeah.net
    http://go5.163.com/~georgezou

  • Executing linux command from Java code

    Hi ,
    I have a web application running on JBoss on Linux platform.
    I need to execut certain shell command of linux through servlet or JSP, so that I can display the command results on UI.
    If you have done something similer sort of thing then please shed some light on it.
    TIA,
    Sachin

    Sorry for the wrong post...please ignore this..
    Thanks,

  • Running linux commands from pl/sql

    Hi, I'm using a java class to run os commands but it doesn't work, i think it's permissions but i cant understand why.
    the java class is the following:
    import java.io.*;
    import java.lang.*;
    public class RunCmd 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];
    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;
    the pl/sql function i created:
    function run_cmd(p_cmd in varchar2) return number as language java name 'RunCmd.RunThis(java.lang.String) return oracle.sql.NUMBER';
    i gave the following permissions:
    begin
    dbms_java.grant_permission(user, 'SYS:java.io.FilePermission', '/home/mails/*', 'execute');
    dbms_java.grant_permission(user, 'SYS:java.io.FilePermission', '/home/mails/*', 'write');
    dbms_java.grant_permission(user, 'SYS:java.io.FilePermission', '/home/mails/*', 'read');
    dbms_java.grant_permission(user, 'SYS:java.io.FilePermission', '/home/mails/*', 'delete');
    dbms_java.grant_permission(user, 'SYS:java.lang.RuntimePermission', '*', 'readFileDescriptor');
    dbms_java.grant_permission(user, 'SYS:java.lang.RuntimePermission', '*', 'writeFileDescriptor');
    Dbms_Java.grant_Permission(user, 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');
    Dbms_Java.grant_Permission(user, 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
    dbms_java.grant_permission(user, 'java.io.FilePermission', '/home/mails/*', 'execute');
    dbms_java.grant_permission(user, 'java.io.FilePermission', '/home/mails/*', 'write');
    dbms_java.grant_permission(user, 'java.io.FilePermission', '/home/mails/*', 'read');
    dbms_java.grant_permission(user, 'java.io.FilePermission', '/home/mails/*', 'delete');
    dbms_java.grant_permission(user, 'java.lang.RuntimePermission', '*', 'readFileDescriptor');
    dbms_java.grant_permission(user, 'java.lang.RuntimePermission', '*', 'writeFileDescriptor' );
    Dbms_Java.grant_Permission(user, 'java.lang.RuntimePermission', 'readFileDescriptor', '');
    Dbms_Java.grant_Permission(user, 'java.lang.RuntimePermission', 'writeFileDescriptor', '');
    commit;
    end;
    The command i'm trying to execute is:
    select run_cmd('/bin/sh -c "ls -ltr /home/mails> /home/mails/teste.txt"') from dual;
    i gave chmod 777 /home/mails and i already run this command directly in console mode and works just fine, so i dont think it's permissions related to the user oracle.
    when i run
    select run_cmd('/bin/sh -c "ls -ltr /home/mails> /home/mails/teste.txt"') from dual;
    it returns 2
    if i run
    select run_cmd('/bin/sh -c ls -ltr /home/mails> /home/mails/teste.txt') from dual;
    it returns 127
    if i run just
    select run_cmd('ls -ltr /home/mails> /home/mails/teste.txt') from dual;
    it returns -1
    if anyone as any clue please, i'm trying to solve this problem for 2 days and i don't have any clue for the solution...

    when i remove the /bin/sh -c it returns -1
    i think that it runs the command because there is a diference in the return value from a valid command a an invalid, for example:
    if i run a valid command
    select k_cs_controlo.run_cmd('/bin/sh -c "ls -ltr /home/mails > /home/mails/teste.txt"') from dual;
    it retuns 2
    if i run an invalid command(removed the " between the ls command)
    select k_cs_controlo.run_cmd('/bin/sh -c ls -ltr /home/mails > /home/mails/teste.txt') from dual
    it returns 127
    thanks for the replies Sven

Maybe you are looking for

  • When i send a message on my 6680 phone, i get this...

    i have a nokia 6680. i sent my phone to fix the camera but unfortunately the guy said it can't be fixed because this is an old phone.that isn't the case, the problem is that since i got it back, i couldn't send sms messages. every time i send a messa

  • How can a change a "permission denied" in a JavaScript use on Facebook ?

    Hi, My problem is : On facebook site, clicking on a result from the "searchbox" doesn't rediret me on that page like it used to ( and should )

  • Factory HA-SKU

    Does anyone know what is the procedure for installing/configuring  a Factory HA-SKU. Mainly how do you configured the primary to see the secondary HA-SKU and vice versa in a N+1 HA/HA-SKU layout.  Thanks   

  • Random roll over with CO Pulse Ticks

    I'm using the 6036E with a random signal (linear encoder) to measure ticks and trigger analog samples.  I have it setup to count 2 rising/falling edges and have the analog input trigger off of the counter's output. The counter is setup for the count

  • SM: System Monitoring for PI7.0

    Now,I'm implemente a Solution Manager project for System monitoring module.who could tell me about how to collect data on part of Java via CCMS? if need to configure CCMS Agent,then how to do it? thanks a lot.