Unable to execute Runtime.getRuntime().exec(

Hello,
I am new to Java programming and trying to execute (OS is Linux) an external jar File with the command:
Runtime.getRuntime().exec("nohup java -jar SeismicAgents.jar &");It should start the SeismicAgents.jar and write the output to nohup.out.
This works perfectly if I just enter the command at the command line.
But upon starting it from within my program, the process seems to be started (I can see it when executin "ps aux"), but it is obviously not running as no input is written to nohup.out and the file which SeismicAgents.jar should generate is not generated.
I also tried the following code:
String cmd[] = {"nohup", "java", "-jar", "SeismicAgents.jar", "&"};
Runtime.getRuntime().exec(cmd);But I am experiencing the same problem here.
Executing something like
Runtime.getRuntime().exec(ls);works without problems...
Can anyone help?

Runtime.getRuntime().exec("nohup java -jar
SeismicAgents.jar &");Java does not interprete the '&' character. Neither does
nohup. You would have to prefix this with /bin/sh -c, put
the rest in quotes and, most importantly, redirect input
and output somewhere. Without redirection, it is the task
of your java program to feed the subprocess with input
and drain its stdout and stderr buffers.
Executing something like
Runtime.getRuntime().exec(ls);works without problems...It is hard to believe this. Either it should be "ls" or
ls is string variable containing the relevant string,
but even then I would be surprised if you see any
output on the command line. At least I don't get
anything with public class bla {
  public static void main(String[] argv) throws Exception {
    Runtime.getRuntime().exec("ls");
}If you don't want a "/bin/sh -c" hack, you may want to
try http://www.ebi.ac.uk/~kirsch/monq-doc/monq/stuff/Exec.html .
Harald.

Similar Messages

  • Unable to run certain commands on unix using the Runtime.getRuntime().exec(

    Hi Folks,
    I am unable to get any output if I try : Runtime.getRuntime().exec("who am i")
    however for Runtime.getRuntime().exec("pwd") I am getting the present working directory path !!!
    if I give Runtime.getRuntime().exec("echo $PATH") then instead of printing the path it prints $PATH instead !!! similarly it is unable to understand any of the special unix characters such as " or ' & is assuming it to be a literal instead.
    Any idea why this is happening ?? and any solution for the same
    regards
    Anand

    I don't think that Runtime.getRuntime().exec() spawns a shell it just executes the file that is specified in the string. ecause of this you can not use commands that are built-in in the shell directly nor use special shell characters. You must spawn your own shell, try something like this:
    Runtime.getRuntime().exec("sh");I'm sure you can add some switch to sh to execute a command by I am not using unix myself so I don't know how. Someone else have to help you with that. You can allways read the man-pages.

  • 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

  • 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

  • Runtime.getRuntime().exec() error message "cannot execute"

    I'm trying to start another program written in c++ with the commands:
    p=Runtime.getRuntime().exec("nameofmyprogram");
    it works with other programs written in java, and also with ordinary unixcommands like "ls" etc. but when I try to start the c++-one I get the message: cannot execute.
    I can start the program directly from the terminal window, so it's ok.
    does anybody have any idea of what I'm doing wrong?
    ( my friend claims that it has to have a name ending with .exe, is that true?)
    grateful for advice!

    My first guess would be that the program is not on the path and Java cannot find the executable, ls on the other hand is on the path..
    I'm assuming that you are running on a unix system as you are using ls, so in this case your program does not need to end in exe, this is a windows thing. If your C++ program compiled on windows it would end in exe, but this is not the case on unix systems.
    I would suggest you try either giving the exec method ./nameofmyprogram assuming java is working in the directory your compiled c++ program. The other is to give the exact location.

  • Executing a command by Runtime.getRuntime.exec().

    Hi,
    I am try to run a java command from one java program. Is it possible
    eg :
    public class A {
    public static void main(String[] args) {
    String startjvm ="java -classpath E:\classes B";
    Runtime.getRuntime.exec(startjvm);
    public class B {
    public static void main(String[] args) {
    System.out.println("Inside the main for class B");
    when i execute the above command from the command line it executes,but when are run the main method for class A nothing happens meaning the message : "Inside the main for class B" is not displayed.
    I also tried displaying the int returned by process.waitfor() method. process is the object returned by the Runtime.getRuntime.exec() method. The int returned is 0 which means the process terminated previously.
    Thanks in advance

    You could get InputStream from created Process and read
    information from it.
    For example
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    public class A {
        public static void main(String[] args) {
            try{
                String startjvm ="java -classpath E:\\classes B";
                Process s = Runtime.getRuntime().exec(startjvm);
                BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
                String line = "";
                while ((line = in.readLine()) != null) {
                    System.out.println(line);
                in.close();
            }catch(Exception e){
                e.printStackTrace();
        }

  • Executing Batch files from Runtime.getRuntime().exec

    Can we execute batch files from Runtime.getRuntime().exec() method.
    Regards,
    Nalini

    hi,
    import java.io.IOException;
    class BatchFileTest{
         public static void main(String args[]){
              try{
              Runtime r = Runtime.getRuntime();
              Process p = r.exec("startcmd.bat");
              catch(IOException en){
                   en.printStackTrace();
    -Regards
    Manikantan

  • 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 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() 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"};

  • Runtime.getRuntime().exec and quoted strings?

    Attempting to execute a command containing a quoted string. Being very new to Java I'm guessing I'm not doing it right. Below are two code bits the first one works the second doesn't. So the question is "How do I use quoted strings in a command with .exec?"
    // this one works
    try {               
    p = Runtime.getRuntime().exec("ls -l tst.java");
    p.waitFor();
    System.out.println("Done!");
    catch(Throwable e) {                                  
    system.out.println("Errors!");
    // this one fails
    try {               
    p = Runtime.getRuntime().exec("ls -l \"tst.java\"");
    p.waitFor();
    System.out.println("Done!");
    catch(Throwable e) {                                  
    system.out.println("Errors!");

    I don't know if it is too late for the answer, but I think I know what the problem is.
    You are using exec(String) method, and passed String parameter is parsed using StringTokenizer class. This means that when you use quotes as in "file1 file2", StringTokenizer parses this as "file1 and then file2" so it is not understandable command.
    To solve the problem, do not use exec(String) method, use exec(String[])
    Using this you can send separate command and separate parameters as in following example:
    If you want to send (in Unix)
    grep "SHOW lotid" text.txt
    (using exec("grep \"SHOW lotid\" text.txt") would not work)
    Do the following
    exec(new String[]{"grep", "SHOW lotid", "text.txt"});
    This avoids parsing problem when quotes are used.
    Mehmed

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

  • Wierdness w/ Runtime().getRuntime().exec between 8.1.6 and 8.1.7

    A Java SP that executes OS commands runs fine in 8.1.6, but doesn't run in
    8.1.7 when a window is generated as a result of the call. The Java class
    follows:
    package com.crtinc.oracle.util.osrun;
    import java.io.*;
    public class SimpleRunner extends Object {
    //just run the daggone command, don't worry about any errors, feedback,
    etc...
    public static void run(String cmd) throws IOException {
    Runtime.getRuntime().exec(cmd);
    The call spec follows:
    CREATE OR REPLACE PACKAGE SIMPLERUNNER AUTHID CURRENT_USER AS
    PROCEDURE RUN ("cmd" IN VARCHAR2)
    AS LANGUAGE JAVA
    NAME 'com.crtinc.oracle.util.osrun.SimpleRunner.run(java.lang.String)';
    END SIMPLERUNNER;
    When deployed to v8.1.6 by a user with JAVASYSPRIV, the following call from
    SQL*Plus runs and displays a window:
    exec simplerunner.run('notepad.exe');
    When deployed to v8.1.7, the same call causes notepad.exe to be added to the NT
    Task Manager Processes tab, but the notepad window doesn't actually open up.
    FWIW, the above code is a simple example - myactual utility captures the
    output streams of OS commands, very much along the lines of sample code that
    I've seen on Metalink - this also works fine in 8.1.6, but never returns in
    8.1.7.
    Granted, running Notepad is of limited utility (though it demos very well :-),
    but other useful OS commands that spawna window (such as kicking of an Oracle
    Report, which pops up a small status window) do not run now in 8.1.7. Running
    a completely non-visual process seemsto work fine, however.
    Any help much appreciated!
    Thanks
    Jim

    Well, just for anyone who might be facing such an issue in the future...
    I am running the databse on NT and it turns out that my NT service didn't have the 'Allow Service to Interact with Desktop' checkbox selected, so that's why OS commands that generated windows weren't showing up. Checking that checkbox and stopping/restarting the service solved the problem.
    Jim
    null

  • How would you capture the stdout of Runtime.getRuntime().exec())?

    How would you capture the stdout of Runtime.getRuntime().exec())?
    Say you wanted to execute PKZIP25.exe from java using Runtime.getRuntime().exec(). How would you capture the output of PKZIP25 (the console IO) in a file so you could check the results?
    Thanks
    Bill Blalock

    Thanks.
    Could you explain a little more?
    The program I am calling seems to be executing, as far as Java is concerned, but nothing happens. I imagine I have made mistakes in calling it but can't see the output to the console.
    Should I use Runtime.getRuntime().exec() or Runtime.exec() for something like this?
    I appreciate the help!
    Bill B.

  • Runtime.getRuntime().exec hangs and doesn't print the output

    Hi,
    I have written the following code to execute the command "psexec ipaddress -u userid -p password -l -c execute.exe >> c:/25_showoutpout.txt" and print the output in 25_showoutpout.txt file.
    import java.io.*;
    public class ExecTest{
         public static void main(String args[]) throws IOException{
         String args1 = "psexec ipaddress -u userid -p password -l -c execute.exe >> c:/25_showoutpout.txt";
         try{
         Process p=Runtime.getRuntime().exec(args1);
    int i = p.waitFor();
         System.out.println("Done.with time "+i);
         }catch(Exception e){
              System.out.println("The error is "+e);
    But this program hangs and creates a blank 25_showoutpout.txt file.In the process list I can see the process running, but it doesn't redirect the output in the txt file.When i run the command from the command line it runs fine.Please help me.
    Thanks in advance

    Hi,
    I have written the following program to get the output.But still the required output is not coming in the console file.Only the messages that gets printed in the parent console that is coming in the file.But the expected output is to get the messages from the child window which gets executed while the .exe runs.
    import java.io.*;
    public class RuntimeExecTest{
    public static void main(String args[]){
    String s = null;
    String result= null;
    int count =0;
    try{
              // read the output from the command
    String cmd = "cmd.exe /c D:/installer/PsTools.zip/PsTools/psexec.exe ipaddress -u userid -p password -l -c excute.exe >> C:/RuntimeExec_25.txt";
         Process p = Runtime.getRuntime().exec(cmd);
         InputStream is = p.getInputStream();
         // Get the std in to the process.
         OutputStream os = p.getOutputStream();
         // Get the std err from the process.
         InputStream es = p.getErrorStream();
         // Create readers for those streams.
         BufferedReader reader = new BufferedReader(new InputStreamReader(is));
         BufferedReader errReader = new BufferedReader(new InputStreamReader(es));
         String line;               
         // Read STDOUT into a buffer.
         // If no STDOUT check STDERR.
         while((line = errReader.readLine()) != null){
              // Do something with data here if you wish.
         System.out.println( line );
         while((line = reader.readLine()) != null){
              // Do something with data here if you wish.
         System.out.println( line );
         System.exit(0);
    catch( Exception ex )
    ex.printStackTrace();
    }

Maybe you are looking for