Runtime.getRuntime().exec() Process question

I saw a website to solve the "hang" of this. It says to use getInputStream()
How come only get the Inpustream and not the OutputStream?
Why is the output of a process that's executed now the InputStream?

It's an InputStream because your program is going to read it.

Similar Messages

  • Using Process Runtime.getRuntime().exec

    http://im1.shutterfly.com/procserv/47b4d633b3127cceb46774c84ee80000001610
    Here is a URL to a part of the current process I need to run. Actually there are 4 steps that preceed these but they are ran in order and must be done before these (that part is easy). Sorry it kinda chopped off the left side a little bit.
    My question is, can I do this entirely using Runtime.getRuntime().exec() commands or do I need to involve multi threading. The reason I am asking is because P13 cannot run until P8 and P9 completes, but that shouldn't stop the rest of the program from running.
    If I have something like
    Process P4 = Runtime.getRuntime().exec(P4);
    Process P5 = Runtime.getRuntime().exec(P2);
    // Some handling for the streams of these processes goes here
    P4.waitFor();
    P2.waitFor();
    if(P2.exitValue() != 0){
    Process P5 = Runtime.getRuntime().exec(P5);
    Process P6 = Runtime.getRuntime().exec(P6);
    // Some handling for the streams of these processes goes here
    Does that mean the whole program will stop and wait until P4 is done before even checking for P2? If P2 is finished would the program continue and run P5 and P6 even if P4 is still running or will it wait for P4 to complete also. P4 has nothing to do with P2?
    Also any advice ???

    P4 and P2 will both be running in parallel (or as much as your OS and hardware allows them to be). As soon as both are done, and regardless of which finishes first, whatever follows P2.waitFor() will execute.
    If you have multiple groups of processes, where the processes within a group must execute sequentially, but the groups themselves can run independently of each other, then you'll need to either use Java's threads, or wrap each group of sequential processes in a shell script or batch file the executes that group sequentially.
    If there are complex dependencies among the groups--that is, multiple groups must wait on the same process, or one group must wait for multiple other groups, then it might be easier to control the concurrency in Java.

  • Process via Runtime.getRuntime().exec(), how to identify that it�s closed?

    A process(console program) is started via Runtime.getRuntime().exec() from Swing Application.
    Swing Application need to know the result of this process.
    So, is there any possibility to find whether the console program is finished?

    Runtime.exec() returns a Process object.
    Look at its methods, especially waitFor(). Read carefully the whole Process documentation, especially what has to be done with the output streams.

  • Kill "runtime.getruntime().exec"-generated processes with control-c?

    Hi there,
    In my java program I create 2 processes with "runtime.getruntime().exec", but when I stop my java program pressing control-c these 2 processes remains running and I have to kill them using linux command "kill".
    How can I program my code in order to kill these 2 processes when stopping my java program with control-c?
    I tried next but it didn't work for me:
            try {
    final Process proc = Runtime.getRuntime().exec ( "java ControlCProblemDemo" );
    Runtime.getRuntime().addShutdownHook(
    new Thread(){
    public void run(){
    proc.destroy();
    while ( true );
    } catch( IOException ioe ) {
    System.err.println( ioe );
    }Thank you very much in advance.
    Josué

    so are you saying proc.destroy() does nothing?
    are you sure it's getting executed?
    is there an error?
    too little info here

  • Runtime.getRuntime().exec question

    Hi
    I have written an program where i need to open files on my computer with specific commands, but it wont work correctly.
    It looks something like this in my Tools class:
    public void setCustomCmd (String cmd) {
              customOpenCmd = cmd;
         public void openCustom (String[] path) {          
              String[] uu = new String[path.length + 1];
              uu[0] = customOpenCmd;
              for (int i = 1;i < uu.length;i++) {
                   uu[i] = path[i - 1];
              try {
                   Process p = Runtime.getRuntime().exec(uu);
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
         }I am trying to open an array of files with the specified command, like some movies with gmplayer. (im using linux, but it would be good to make this method platform independent). The thing is it "kind of" works. When i give an array with paths to smplayer (an frontend for mplayer) they will be added to the playlist and i can play the movies, but smplayer behaves strange. When i try to open the settings or the file info for instance, smplayer just freezes. Gmplayer also "kind of" works, until i try to close it. It will freeze and i have to kill the process. (in both cases the movie still plays, but the frontend for mplayer itself freezes).
    So far i have been able to solve every problem in my learning process of java (and programming in general) with google, but im just unable to make any progress with this problem (and i REALLY have tried everything i can think of). So, can anyone help me?
    Also, smplayer does write some output to the terminal when i run it, do i need to handle that from java somehow as well?
    Thanks in advice.

    Hah! now i managed to make it work perfectly. Here is my code (maybe its a bit ugly since I'm quite new to programming in general, but it may help someone who tries to accomplish the same thing):
    public void setCustomCmd (String cmd) {
              customOpenCmd = cmd;
         public void openCustom (String[] path) {          
              String[] uu = new String[path.length + 1];
              uu[0] = customOpenCmd;
              for (int i = 1;i < uu.length;i++) {
                   uu[i] = path[i - 1];
              RunCmd zzz = new RunCmd(uu);
              zzz.start();
         private class RunCmd extends Thread
             Process proc;
             String[] cmd;
             RunCmd(String[] cmdIn)
                cmd = cmdIn;
             public String[] getCmd() {
                  return cmd;
             public boolean setCmd(String[] cmdIn) {
                  // Don't change the command in case this thread is alive.
                  if (this.isAlive()) {
                       return false;
                  cmd = cmdIn;
                  return true;
             public void run()
                  try
                       // Execute the command in run to avoid problems in case someone forgets to call
                       // run and the process "kind of" works as an result.
                       Runtime rt = Runtime.getRuntime();
                       proc = rt.exec(cmd);
                     // any error message?
                     StreamGobbler errorGobbler = new
                         StreamGobbler(proc.getErrorStream(), "ERR");           
                     // any output?
                     StreamGobbler outputGobbler = new
                         StreamGobbler(proc.getInputStream(), "OUT");
                     // kick them off
                     errorGobbler.start();
                     outputGobbler.start();
                     // any error???
                     int exitVal = proc.waitFor();
                     log.print(customOpenCmd + ":<BR>" + "<font color=green>ExitValue: " + exitVal + "</font color=green>");
                     log.print("");
                 } catch (Throwable t)
                     t.printStackTrace();
         private class StreamGobbler extends Thread
             InputStream is;
             String type;
             OutputStream os;
             StreamGobbler(InputStream is, String type)
                 this(is, type, null);
             StreamGobbler(InputStream is, String type, OutputStream redirect)
                 this.is = is;
                 this.type = type;
                 this.os = redirect;
             public void run()
                 try
                     PrintWriter pw = null;
                     if (os != null)
                         pw = new PrintWriter(os);
                     InputStreamReader isr = new InputStreamReader(is);
                     BufferedReader br = new BufferedReader(isr);
                     String line=null;
                     while ( (line = br.readLine()) != null)
                         if (pw != null)
                             pw.println(line);
                         System.out.println(customOpenCmd + ": " + type + ">" + line);
                         // log.printNoTime(customOpenCmd + ": " + type + ">" + line); So much output, my log is 2 slow :p
                     if (pw != null)
                         pw.flush();
                 } catch (IOException ioe)
                     ioe.printStackTrace(); 
         }This executes the command and lets the program continue even if the execition still runs. I have only tried this a few times, so if i encounter problems with this code i will post the solution if i manage to find it.

  • Runtime.getRuntime().exec() - native process

    Hi,
    I want to start a native (openFt) program from within my servlet. Therefore, I use Runtime.getRuntime().exec(String [] cmd). This works fine in my local OC4J container: the process is terminated with error code 0 and the native program is executed. The only strange thing here is that the output text isn't in my InputStream but in my ErrorStream.
    The real problem arises when I deploy the same Ear on the 9ias server. Here, the process doesn't execute my native command, terminates with error code 128 and leaves no inputStream and no errorStream.
    Errorcode 128 means that there are no child processes to wait for. (i call process.waitFor() to obtain the error code). I think this means my process isn't even started.
    Anyone familiar with processes in OC4J & 9IAS?
    Thanx in advance

    I guess your implementation of matchIp() is wrong:
    public class ReaderTest {
        public static void main(String[] args) {
            new ReaderTest().testReaderMethod();
        private void testReaderMethod() {
            ByteArrayInputStream dummyStrem = new ByteArrayInputStream(
                    ("*******************************************\n"
                            + "*   My shell Application                   *\n"
                            + "\n"
                            + "*******************************************\n"
                            + "\n" + " \n" + "\n" + "HELP: h\n" + "\n"
                            + "COMMAND: c\n" + "\n" + "QUIT:q\n" + "\n"
                            + "135.19.45.18> ").getBytes());
            System.out.println(readUntilIpMatch(dummyStrem));
        private StringBuilder buffer = new StringBuilder();
        protected String readUntilIpMatch(final InputStream in) {
            while (true) {
                try {
                    if (in.available() > 0) {
                        buffer.append((char) in.read());
                        Pattern pattern = Pattern
                                .compile("\\d{1,3}(\\.\\d{1,3}){3}(?=\\D)");
                        Matcher matcher = pattern.matcher(buffer);
                        if (matcher.find()) {
                            return matcher.group();
                } catch (final IOException e) {
                    throw new RuntimeException(
                            "Failed to read buffer in while looking for prompt!", e);
        } // runs forever if not matching!!!!
    bye
    TPD

  • SWT window disappear while running Runtime.getRuntime().exec()

    Hello,
    I have create a SWT application. I am executing the folloiwng code from my SWT application.
    Process process = Runtime.getRuntime().exec(param);
    BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
    String line = null;
    while ((line = in.readLine()) != null) {
    During execution of the above code when click on other icon of the window task bar and click back on SWT window Icon, The windows open but it does not show annything until the code execution finish. any help would be apprecited.

    This isn't an SWT forum. In the future, please post such questions on a forum specifically for SWT issues.
    But to answer your question, there's a 99.9% chance this is because you're launching the process on SWT's UI thread. Similar to performing long-running tasks on Swing's EDT, this is a no-no. The SWT UI won't be able to repaint itself until after your process has finished. To remedy this, launch your process in a separate Thread.

  • Swign application and Runtime.getRuntime().exec(cmd)

    i want to use this program in a swing application, when i press the button it will execute this comand,?? is possible?
    String[] cmd = {"pwd","ls"};
    try {
    Process ls = Runtime.getRuntime().exec(cmd);
    BufferedReader input1 = new BufferedReader(new InputStreamReader(ls.getInputStream()));
    String str = input1.readLine();
    /* Keep looping until we have read all of the output */
    while(str != null) {
    System.out.println(str);
    str = input1.readLine();
    } catch (java.io.IOException el) {
    System.err.println(el);
    import javax.swing.*;
    import java.awt.event.*;
    public class Main{
    JFrame frame;
    public static void main(String[] args){
    Main db = new Main();
    public Main(){
    frame = new JFrame("Show Message Dialog");
    JButton button = new JButton("Click Me");
    button.addActionListener(new MyAction());
    frame.add(button);
    frame.setSize(400, 400);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    public class MyAction implements ActionListener{
    public void actionPerformed(ActionEvent e){
    JOptionPane.showMessageDialog(frame,"hello");
    }

    its pretty hard to read without code tags,
    if your questions is can i use this code in my new swing applications when i press a button
    sure you can you need to make your new program with actionlisterners, your button will then wait until you click on it,
    then you will call your old method when the button is clicked
    I think that what you want sorry if i got the wrong end of the stick

  • Runtime.getRuntime().exec

    hi all,
    im running my java under Linux.
    i want to copy a big bulk of files from one folder to other folder.
    when i implement Runtime.getRuntime().exec("cp -r /sourcefolder /destintationfolder").
    its been execute but the copy process didnt complete yet.
    is there any way to be sure that the command finished, so i can be sure the command finish its work.
    TIA

    Gabi wrote:
    ..please do not answer .Please do not ask dumb, poorly researched, poorly thought out questions then expect people to rush to your service.
    This is not your personal help desk.

  • Runtime.getRuntime().exec() problem while getting Mozilla version.

    Hi all,
    I've trying to get the current mozilla version in Java side using
    Runtime.getRuntime().exec(). The sample code is as below.
    I've tested two cases using exec(), as case# 1 and case# 2.
    The result is after the code.
    try
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec(new String[] {"mozilla", "-remote"}); //case# 1
    //Process proc = rt.exec(new String[] {"mozilla", "-version"}); //case# 2
    InputStream stderr = proc.getErrorStream();
    InputStreamReader isr = new InputStreamReader(stderr);
    BufferedReader br = new BufferedReader(isr);
    String line = null;
    System.out.println("<ERROR>");
    while ( (line = br.readLine()) != null)
    System.out.println(line);
    System.out.println("</ERROR>");
    int exitVal = proc.waitFor();
    System.out.println("Process exitValue: " + exitVal);
    } catch (Throwable t) {
    t.printStackTrace();
    // execute "mozilla -remote"(case# 1)
    $ java TestExec
    <ERROR>
    -remote requires an argument
    </ERROR>
    Process exitValue: 1
    // execute "mozilla -version"(case# 2)
    $ java TestExec
    <ERROR>
    </ERROR>
    Process exitValue: 0
    I'm just surprised that why case# 2 couldn't get the returned version string as case #1 ? Since there will be version string be returned from command line:
    $ mozilla -version
    Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.1) Gecko/20020830, build 2002083014
    Could anybody explain the problem or give any solution ?
    Thanks.
    -George.

    Hi all,
    One more question here.
    While I use Runtime.getRuntime().exec() to execute some commands,
    the commands may fail for some reason. Generally, they will return with the exit
    value set to 1 or others. But sometime, before waitFor() exits, there is a popped up
    dialog giving some info, and only after I click the "OK" button, it dispears, and
    waitFor() returns the exit value.
    So I'm not sure that could I suppress this popped up dialog, and make it run
    just like other commands ? I mean, just get the exit value by waitFor() without user
    interferance ?
    Thanks.
    -George.

  • How to execute an application in Solaris using Runtime.getRuntime.exec() ?

    I am currently doing a project which requires the execution of Solaris applications through the use of Java Servlet with this Runtime method - Runtime.getRuntime.exec()
    This means that if the client PC tries to access the servlet in the server PC, an application is supposed to be executed and launched on the server PC itself. Actually, the servlet part is not an issue as the main problem is the executing of applications in different platforms which is a big headache.
    When I tried running this program on a Windows 2000 machine, it works perfectly fine. However, when I tried it on a Solaris machine, nothing happens. And I mean nothing... no errors, no nothing. I really don't know what's wrong.
    Here's the code.
    public void doPost(HttpServletRequest request, HttpServletResponse response)
         throws ServletException, IOException
         response.setContentType("text/html");
         PrintWriter out = response.getWriter();
              Process process;                                                       Runtime runtime = Runtime.getRuntime();
              String com= "sh /opt/home/acrobat/";
              String program = request.getParameter("program");
              try
                        process = runtime.exec(com);
              catch (Exception e)
                   out.println(e);
    It works under Windows when com = "c:\winnt\system32\notepad.exe"
    When under Solaris, I have tried everything possible. For example, the launching of the application acrobat.
    com = "/opt/home/acrobat"
    com = "sh /opt/home/acrobat"I have also tried reading in the process and then printing it out. It doesn't work either. It only works when excuting commands like 'ls'
    BufferedReader read = new BufferedReader(new InputStreamReader(process.getInputStream()));Why is it such a breeze to execute prgrams under Windows while there are so many problems under Solaris.
    Can some experts please please PLEASE point out the errors and give me some advice and help to make this program work under Solaris! Please... I really need to do this!!
    My email address - [email protected]
    I appreciate it.
    By the way, I'm coding and compiling in a Windows 2000 machine before ftp'ing the .class file to the Solaris server machine to run.

    it is possible that you are trying to run a program that is going to display a window on an X server, but you have not specified a display. You specifiy a display by setting the DISPLAY environment variable eg.
    setenv DISPLAY 10.0.0.1:0
    To check that runtime.exec is working you should try to run a program that does not reqire access to an X Server. Try something like
    cmd = "sh -c 'ls -l > ~/testlist.lst'";
    alternatively try this
    cmd = "sh -c 'export DISPLAY=127.0.0.1:0;xterm '"
    you will also need to permit access to the X server using the xhost + command

  • How to get return value from Java runtime.getRuntime.exec?

    I'm running shell commands from an Oracle db (11gr2) on aix.
    But, I would like to get a return value from a shell comand... like you get with "echo $?"
    I use a code like
    CREATE OR REPLACE JAVA SOURCE NAMED common."Host" AS
    import java.io.*;
    public class Host {
      public static int executeCommand(String command) {
        int retval=0;
        try {
            String[] finalCommand;
            finalCommand = new String[3];
            finalCommand[0] = "/bin/sh";
            finalCommand[1] = "-c";
            finalCommand[2] = command;
          final Process pr = Runtime.getRuntime().exec(finalCommand);
          pr.waitFor();
       catch (Exception ex) {
          System.out.println(ex.getLocalizedMessage());
          retval=-1;
        return retval;
    /but I do not get a return value... because I don't know how to get return value..
    Edited by: user9158455 on 22-Sep-2010 07:33

    Hi,
    Have your tried pr.exitValue() ?
    I think you also need a finally block that destroys the subprocess
    Regards
    Peter

  • Strange behaviour of Runtime.getRuntime().exec(command)

    hello guys,
    i wrote a program which executes some commands in commandline (actually tried multiple stuff.)
    what did i try?
    open "cmd.exe" manually (administrator)
    type "echo %PROCESSOR_ARCHITECTURE%" and hit enter, which returns me
    "AMD64"
    type "java -version" and hit enter, which returns me:
    "java version "1.6.0_10-beta"
    Java(TM) SE Runtime Environment (build 1.6.0_10-beta-b25)
    Java HotSpot(TM) 64-Bit Server VM (build 11.0-b12, mixed mode)"
    type "reg query "HKLM\SOFTWARE\7-zip"" returns me:
    HKEY_LOCAL_MACHINE\SOFTWARE\7-zip
    Path REG_SZ C:\Program Files\7-Zip\
    i wrote two functions to execute an command
    1) simply calls exec and reads errin and stdout from the process started:
    public static String execute(String command) {
              String result = "";
              try {
                   // Execute a command
                   Process child = Runtime.getRuntime().exec(command);
                   // Read from an input stream
                   InputStream in = child.getInputStream();
                   int c;
                   while ((c = in.read()) != -1) {
                        result += ((char) c);
                   in.close();
                   in = child.getErrorStream();
                   while ((c = in.read()) != -1) {
                        result += ((char) c);
                   in.close();
              } catch (IOException e) {
              return result;
         }the second function allows me to send multiple commands to the cmd
    public static String exec(String[] commands) {
              String line;
              String result = "";
              OutputStream stdin = null;
              InputStream stderr = null;
              InputStream stdout = null;
              // launch EXE and grab stdin/stdout and stderr
              try {
                   Process process;
                   process = Runtime.getRuntime().exec("cmd.exe");
                   stdin = process.getOutputStream();
                   stderr = process.getErrorStream();
                   stdout = process.getInputStream();
                   // "write" the parms into stdin
                   for (int i = 0; i < commands.length; i++) {
                        line = commands[i] + "\n";
                        stdin.write(line.getBytes());
                        stdin.flush();
                   stdin.close();
                   // clean up if any output in stdout
                   BufferedReader brCleanUp = new BufferedReader(
                             new InputStreamReader(stdout));
                   while ((line = brCleanUp.readLine()) != null) {
                        result += line + "\n";
                   brCleanUp.close();
                   // clean up if any output in stderr
                   brCleanUp = new BufferedReader(new InputStreamReader(stderr));
                   while ((line = brCleanUp.readLine()) != null) {
                        result += "ERR: " + line + "\n";
                   brCleanUp.close();
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              return result;
         }so i try to execute the commands from above (yes, i am using \\ and \" in java)
    (1) "echo %PROCESSOR_ARCHITECTURE%"
    (2) "java -version"
    (3) "reg query "HKLM\SOFTWARE\7-zip""
    the first function returns me (note that ALL results are different from the stuff above!):
    (1) "" <-- empty ?!
    (2) java version "1.6.0_11"
    Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
    Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode, sharing)
    (3) ERROR: The system was unable to find the specified registry key or value.
    the second function returns me:
    (1) x86 <-- huh? i have AMD64
    (2) java version "1.6.0_11"
    Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
    Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode, sharing)
    (3) ERROR: The system was unable to find the specified registry key or value.
    horray! in this version the java version is correct! processor architecture is not empty but totally incorrect and the reg query is still err.
    any help is wellcome
    note: i only put stuff here, which returns me strange behaviour, most things are working correct with my functions (using the Runtime.getRuntime().exec(command); code)
    note2: "reg query "HKLM\HARDWARE\DESCRIPTION\System\CentralProcessor\0" /t REG_SZ" IS working, so why are "some" queries result in ERR, while they are working if typed by hand in cmd.exe?

    ok, i exported a jar file and execute it from cmd:
    java -jar myjar.jar
    now the output is:
    (1) "" if called by version 1, possible to retrieve by version 2 (no clue why!)
    (2) "java version "1.6.0_10-beta"
    Java(TM) SE Runtime Environment (build 1.6.0_10-beta-b25)
    Java HotSpot(TM) 64-Bit Server VM (build 11.0-b12, mixed mode)"
    (3) C:\Program Files\7-Zip\
    so all three problems are gone! (but its a hard way, as i need both functions and parse a lot of text... :/ )
    thanks for the tip, that eclipse changes variables (i really did not knew this one...)

  • Runtime.getRuntime.exec() not working when Tomcat is made a windows Sevice

    Hi,
    I am working on a web application which launches a exe file on subitting the form. I am using Apache Tomcat 4.0.6 to run the web application. Initially Tomcat was not made a windows service on my machine and when I launch an exe it is launching without any problems. I used the following command to launch the exe file:
    <code>
    Process p = Runtime.getRuntime().exec("C:\\Program Files\\Mercury Interactive\\WinRunner\\arch\\wrun.exe" + strWROptions);
    </code>
    The above command launches WinRunner on the local machine.
    without using tomcat if I just compile and run a test program with this command, the exe is launching perfectly. But, Once I made tomcat a windows service on my machine the exe is not launching.
    Also, a process is being created in the windows task bar named wrun.exe once I submit the form but WinRunner is not lauching on the desktop.
    Can any one please help and suggest me.
    Thanks,
    Ramesh

    The version of Java I am using is 1.4.2. Even without
    using the string array as you mentioned, the exe
    (wrun.exe) is launched on my desktop if I don't run
    Tomcat as a windows service. But the problem arises on
    making it a service :-(
    That is strange because going by the documentation what you have been using should never work. I can't test it though, I'm not on MSWindows at the moment..
    Now, when I use this string array convention, I am
    getting an error saying "The tool could not launch..
    some error occured".
    That's not a Java error message, it must come from WinRunner. This means that you have succesfully started WinRunner (great!) but something else is wrong; maybe the parameters you pass to it are incorrect.
    How would you run it on the command line? Like this?wrun -t "D:\L5_QE\L5A\Initial" -create_text_report on -runThat line executes the wrun program and passes it five parameters, not three. The first parameter is "-t", the second "D:\L5_QE\L5A\Initial", the third "-create_text_report", the fourth "on", and the fifth "-run". The array of strings that corresponds to that line isString[] command = {"C:\\Program Files\\Mercury Interactive\\WinRunner\\arch\\wrun.exe",
                    "-t", "D:\\L5_QE\\L5A\\Initial",
                    "-create_text_report", "on",
                    "-run"};

  • PROBLEM in executing a shell command through Runtime.getRuntime().exec()

    Hi all,
    I was trying to execute the following code:
    import java.io.BufferedReader;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.sql.CallableStatement;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.Statement;
    import java.sql.ResultSet;
    * Created on Mar 13, 2007
    * To change the template for this generated file go to
    * Window>Preferences>Java>Code Generation>Code and Comments
    * @author 195092
    * To change the template for this generated type comment go to
    * Window>Preferences>Java>Code Generation>Code and Comments
    public class ClassReportDeleteDaemon {
         ClassReportDeleteDaemon()
         public static void main(String[] args) throws Exception
              Connection conn = null;
              Statement stmt = null;
              ResultSet rs;
              String strQuery = null;
              String strdaysback = null;
              String delstring = null;
              int daysback;
              try
                   System.out.println("REPORT DELETION ::: FINDING DRIVER");               
                   Class.forName("oracle.jdbc.driver.OracleDriver");
              catch(Exception e)
                   System.out.println("REPORT DELETION ::: DRIVER EXCEPTION--" + e.getMessage());
                   System.out.println("REPORT DELETION ::: DRIVER NOT FOUND");
              try
                   String strUrl = "jdbc:Oracle:thin:" + args[0] + "/" + args[1] + "@" + args[2];
                   System.out.println("REPORT DELETION ::: TRYING FOR JDBC CONNECTION");
                   conn = DriverManager.getConnection(strUrl);
                   System.out.println("REPORT DELETION ::: SUCCESSFUL CONNECTION");
                   while(true)
                        System.out.println("WHILE LOOP");
                        stmt = conn.createStatement();
                        strQuery = "SELECT REP_DAYS_OLD FROM T_REPORT_DEL";
                        rs = stmt.executeQuery(strQuery);
                        while(rs.next())
                             strdaysback = rs.getString("REP_DAYS_OLD");
                             //daysback = Integer.parseInt(strdaysback);
                        System.out.print("NO of Days===>" + strdaysback);
                        delstring = "find /tmp/reports1 -name " + "\"" + "*" + "\"" + " -mtime +" + strdaysback + " -print|xargs rm -r";
                        System.out.println("DELETE STRING===>" + delstring);
                        Process proc = Runtime.getRuntime().exec(delstring);
                        //Get error stream to display error messages encountered during execution of command
                        InputStream errStream=proc.getErrorStream();
                        //Get error stream to display output messages encountered during execution of command
                        InputStream inStream = proc.getInputStream();
                        InputStreamReader strReader = new InputStreamReader(errStream);
                        BufferedReader br = new BufferedReader(strReader);
                        String strLine = null;
                        while((strLine=br.readLine())!=null)
                             System.out.println(strLine);
                   }     //end of while loop
              }     //end of try
              catch (Exception e)
                   System.out.println("REPORT DELETION ::: EXCEPTION---" + e.getMessage());
                   conn.close();
         }     //end of main
    }     //end of ClassReportDeleteDaemon
    But it is giving the error "BAD OPTION -print|xargs". The command run well in shell.
    Please help.
    Thanking u.......

    Since the pipe '|' is interpreted by the shell then you need the shell to invoke your command
            String[] command = {"sh","-c","find /tmp/reports1 -name " + "\"" + "*" + "\"" + " -mtime +" + strdaysback + " -print|xargs rm -r"};
            final Process process = Runtime.getRuntime().exec(command);
      You should also read http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html at least twice and implement the recommendation regarding stdout and stderr.
    P.S. Why are you not using Java to find and delete these files?
    Message was edited by:
    sabre150

Maybe you are looking for

  • Voice Over Recording Edit view vs Multitrack View

    Hi Guys, need some advice here. I have always recorded Voice Overs in edit view with Audition 3.0 (Windows 7 64bit) Recently I purchased a Creative sound card (X-Fi Titanium HD) which sounds great and records 24/96Khz with great results using several

  • Problems with User Queries

    Hi everybody, i recieved an error while try to run a user query in Business One which works fine in SQL Studio. DECLARE @PROJECT as nvarchar(128) SET @PROJECT = '[%0]' select query2.docnum, query2.DocStatus, query2.CardCode, query2.CardName, query2.D

  • Authorisation objects - FICO

    Hi experts, I need to find the list of Authorisation objects for FI & CO. If I go by table, How do i restrict for FI alone. kindly suggest the best way to find the authorisation objects. I have to create a authorisation matrix and where i can find a

  • Item on the listbox cant be selected. PLS HELP.

    hello! i am a newbie to ABAP development. I followed the listbox steps stated on the RSDEMO_DROPDOWN_LISTBOX because I want to populate my listbox (I created from the screen painter) with the data from a table. It was successful and I can see the dat

  • Possible issue with DFS and CSC error 80070035

    I have a handful of users who have a strange, recurring issue with Offline Files and DFS in Win7 SP1 x64. We have a DFS root \\domain.local\DFS. Server ukln1fs1 is a root replica, running a fully patched instance of Server 2012 R2. dfsnamespace is a