System.getRuntime().exec() sometimes hangs on Solaris 10 u4...

Hi everyone, I have a multi-threaded application that basically starts external programs ( bash scripts ) using Runtime.getRuntime().exec(unixCmd); The thread waits for the process to finish and when it does, returns the return code from the process. During peak period, it's not rare that the program reaches at least 5 concurrent threads, therefore 5 process are running at the same time.
We used to run this program on Solaris 10 u2 using Java 1.5.0_6 and we never had any problem whatsoever. Recently, we moved the application to a new server running on Solaris 10 u4 using Java 1.5.0.15 and the problems started... We observed that about 1% of all the process launched hang. Even the destroy() method of the process has no effect. The only way to stop the process is with the cmd kill -9. We also observed that the script called by the application is not executed at all, not even the first line.
Here is my code:
    Runtime shell = Runtime.getRuntime();
    Process proc = shell.exec(cmd_unix_final);
    if (Server.getProperty(PROP_LOG_ENABLED).toLowerCase().equals("true"))
      outputGobbler = new StreamGobbler(proc.getInputStream(), Server.getProperty(PROP_LOG_OUTPUT_FILE), Server.getPhase());
      errorGobbler = new StreamGobbler(proc.getErrorStream(), Server.getProperty(PROP_LOG_ERROR_FILE), Server.getPhase());
      outputGobbler.start();
      errorGobbler.start();
    do
      try
        returnValue = proc.exitValue();
        processFinished = true;
      catch (IllegalThreadStateException e)
        try { Thread.sleep(sleepInterval);}catch(InterruptedException ex){ex.printStackTrace();}
    while (System.currentTimeMillis() - launchTime < threadTimeout * 1000 * 60 && !processFinished);
    if (!processFinished)
      proc.destroy();
      returnValue = ServerReturnCodes.SERVER_RETURN_CODE_TIMEOUT_ERROR;
    return returnValue;
...If you have any idea what is causing the problem, please let me know, thanks!

Thank you both for your replys. We are going to try an other version of Java soon... As for the process, the bash script does not even gets executed, the process hangs before that, at the creation phase.

Similar Messages

  • Runtime.getRuntime.exec() may hang?

    Hi, I am trying to run a Microsoft application, suspend.exe, under Java, on xp. I noticed that sometimes the program would hang, after issuing the command.
    String command = "cmd /c suspend.exe -n 15 -s 3 -l c:\\scpt\\s3.txt -e " ;
    suspend = Runtime.getRuntime().exec (command);
    Is there a compatibility between MS and Java after Java releases the control to the native environment? Has anyone seen this? Sometimes this gets kicked off, and sometimes it doesn't.
    * I am really confused. Thanks for any help

    thank you, I will look into this.
    Btw, do you know how to start a java program at start up? I have searched and read some articles, but none seems to do the trick for me.
    I have:
    1) create a bat file. This bat file runs fine w/ double clicking, but when trying to place it in startup folder and run it, it quits.
    2) create a simple c vesion of .exe file. This possesses the same behavior as above
    3) create a short cut to the bat file and place it in startup folder. Nothing happens.
    4) add reg. key in regedit with
    'java Pclient'
    and
    'java c:\scpt\Pclient'
    nothing seems to happen.
    still searching...
    thank you.

  • Running java process in a while loop using Runtime.exec() hangs on solaris

    I'm writting a multithreaded application in which I'll be starting multiple instances of "AppStartThread" class (given below). If I start only one instance of "AppStartThread", it is working fine. But if I start more than one instance of "AppStartThread", one of the threads hangs after some time (occasionaly). But other threads are working fine.
    I have the following questions:
    1. Is there any problem with starting a Thread inside another thread?. Here I'm executing the process in a while loop.
    2. Other thing i noticed is the Thread is hanging after completing the process ("java ExecuteProcess"). But the P.waitFor() is not coming out.
    3. Is it bcoz of the same problem as given in Bug ID : 4098442 ?.
    4. Also java 1.2.2 documentation says:
    "Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock. "
    I'm running this on sun Solaris/java 1.2.2 standard edition. If any of you have experienced the same problem please help me out.
    Will the same problem can happen on java 1.2.2 enterprise edition.?
    class AppStartThread implements Runnable
    public void run()
    while(true)
    try
    Process P=Runtime.getRuntime().exec("java ExecuteProcess");
    P.waitFor();
    System.out.println("after executing application.");
    P.destroy();
    P = null;
    System.gc();
    catch(java.io.IOException io)
    System.out.println("Could not execute application - IOException " + io);
    catch(java.lang.InterruptedException ip)
    System.out.println("Could not execute application - InterruptedException" + ip);
    catch (Exception e)
    System.out.println("Could not execute application -" + e.getMessage());

    I'm writting a multithreaded application in which I'll
    be starting multiple instances of "AppStartThread"
    class (given below). If I start only one instance of
    "AppStartThread", it is working fine. But if I start
    more than one instance of "AppStartThread", one of the
    threads hangs after some time (occasionaly). But other
    threads are working fine.
    I have the following questions:
    1. Is there any problem with starting a Thread inside
    another thread?. Here I'm executing the process in a
    while loop.Of course this is OK, as your code is always being run by one thread or another. And no, it doesn't depend on which thread is starting threads.
    2. Other thing i noticed is the Thread is hanging
    after completing the process ("java ExecuteProcess").
    But the P.waitFor() is not coming out.This is a vital clue. Is the process started by the Runtime.exec() actually completing or does the ps command still show that it is running?
    3. Is it bcoz of the same problem as given in Bug ID :
    4098442 ?.
    4. Also java 1.2.2 documentation says:
    "Because some native platforms only provide limited
    ed buffer size for standard input and output streams,
    failure to promptly write the input stream or read the
    output stream of the subprocess may cause the
    subprocess to block, and even deadlock. "These two are really the same thing (4098442 is not really a bug due to the reasons explained in the doc). If the program that you are exec'ing produces very much output, it is possible that the buffers to stdout and stderr are filling preventing your program from continuing. On Windows platforms, this buffer size is quite small (hundreds of characters) while (if I recall) on Solaris it is somewhat larger. However, I have seent his behavior causing problem on Solaris 8 in my own systems.
    I once hit this problem when I was 'sure' that I was emitting no output due to an exception being thrown that I wasn't even aware of - the stack trace was more than enough to fill the output buffer and cause the deadlock.
    You have several options. One, you could replace the System.out and System.err with PrintStream's backed up by (ie. on top of) BufferedOutputStream's that have large buffers (multi-K) that in turn are backed up by the original out and err PrintStream's. You would use System.setErr() and System.setOut() very early (static initializer block) in the startup of your class. The problem is that you are still at the mercy of code that may call flush() on these streams. I suppose you could implement your own FilterOutputStream to eat any flush requests...
    Another solution if you just don't care about the output is to replace System.out and System.err with PrintStreams that write to /dev/nul. This is really easy and efficient.
    The other tried and true approach is to start two threads in the main process each time you start a process. These will simply consume anything that is emitted through the stdout and stderr pipes. These would die when the streams close (i.e. when the process exits). Not pretty, but it works. I'd be worried about the overhead of two additional threads per external process except that processes have such huge overhead (considering you are starting a JVM) that it just won't matter. And it's not like the CPU is going to get hit much.
    If you do this frequently in your program you might consider using a worker thread pool (see Doug Lea's Executor class) to avoid creating a lot of fairly short-lived threads. But this is probably over-optimizing.
    Chuck

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

  • Using getRuntime().exec() with Serlvet to run applications in Solaris

    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.

    Hi!
    I'm no expert, but I think I remember doing something similar a few months ago, and I think the problem was that the UNIX server does not know which shell to use. The solution was this:
    Create a script that starts the program on the server, and be sure to include a first row saying:
    #!/bin/ksh
    to specify which shell to use (in this case Korn shell). Then call the script from Runtime.getRuntime().exec()

  • 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

  • Runtime.exec() hangs on solaris 10, deadlock in soft_delete_session ?

    Hi,
    In my application sometimes Runtime.exec calls hangs for ever.
    The pstack of java process is at the end of the post. It seems like there is a deadlock in soft_delete_session.
    Does anyone know of any java/os patch we can apply to fix this issue?
    I will really appreciate any tips to get over this issue.
    # uname -a
    SunOS thor256 5.10 Generic_120011-14 sun4u sparc SUNW,Sun-Fire-V245
    # /opt/VRTSjre/jre1.5/bin/java -version
    java version "1.5.0_10"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_10-b03)
    Java HotSpot(TM) Server VM (build 1.5.0_10-b03, mixed mode)
    The trace is as follows:
    0xff340408 __lwp_park + 0x10
    0xff339068 mutex_lock_internal + 0x5d0
    0xfb08a2ec soft_delete_session + 0xf0
    0xfb089f90 soft_delete_all_sessions + 0x4c
    0xfb084348 finalize_common + 0x70
    0xfb0844d8 softtoken_fini + 0x44
    0xfb0d8d48 _fini + 0x4
    0xff3c00d0 call_fini + 0xc8
    0xff3ca614 remove_hdl + 0xab8
    0xff3c4d54 dlclose_intn + 0x98
    0xff3c4e68 dlclose + 0x5c
    0xfb3a2b3c pkcs11_slottable_delete + 0x138
    0xfb39d664 pkcs11_fini + 0x4c
    0xff2c0ea0 postforkchild_handler + 0x30
    0xff332c20 fork + 0x140
    0xfe8f8df4 Java_java_lang_UNIXProcess_forkAndExec + 0x7d4
    0xf9226020 0xf9226020 * java.lang.UNIXProcess.forkAndExec(byte[], byte[], int, byte[], int, byte[], boolean, java.io.FileDescriptor, java.io.FileDescriptor, java.io.FileDescriptor) bci:0 (Compiled frame; information may be imprecise)
    0xf92216c4 0xf92216c4 * java.lang.UNIXProcess.(byte[], byte[], int, byte[], int, byte[], boolean) bci:62 line:53 (Compiled frame)
    0xf90fa6b8 0xf90fa6b8 * java.lang.ProcessImpl.start(java.lang.String[], java.util.Map, java.lang.String, boolean) bci:182 line:65 (Compiled frame)
    0xf90fbe0c 0xf90fbe0c * java.lang.ProcessBuilder.start() bci:112 line:451 (Compiled frame)
    0xf921842c 0xf921842c * java.lang.Runtime.exec(java.lang.String[], java.lang.String[], java.io.File) bci:16 line:591 (Compiled frame)
    0xf9005874 * java.lang.Runtime.exec(java.lang.String[]) bci:4 line:464 (Interpreted frame)
    0xf9005874 * TestExec.run() bci:26 line:22 (Interpreted frame)
    0xf9005c2c * java.lang.Thread.run() bci:11 line:595 (Interpreted frame)
    0xf9000218
    0xfecdca88 void JavaCalls::call_helper(JavaValue*,methodHandle*,JavaCallArguments*,Thread*) + 0x5b8
    0xfecf4310 void JavaCalls::call_virtual(JavaValue*,Handle,KlassHandle,symbolHandle,symbolHandle ,Thread*) + 0x18c
    0xfecf416c void thread_entry(JavaThread*,Thread*) + 0x12c
    0xfecf3ff0 void JavaThread::run() + 0x1f4
    0xff02fb30 void*_start(void*) + 0x200
    0xff340368 lwpstart

    Found this information about this problem:
    Bug: http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=6276483
    Info for patch 127111-11: http://sunsolve.sun.com/search/document.do?assetkey=1-21-127111-11-1
    Download page: http://sunsolve.sun.com/show.do?target=patches/zos-s10

  • Runtime.getRuntime().exec("/usr/bin/env") crashes on Solaris

    I am trying to write a Java class to read environment variables on Solaris. I have read a few posts on this forum and it appears that other people have had no trouble in doing this. I have written the following code to execute the unix 'env' command and read in the standard input stream from the output.
    // start
    Process process = Runtime.getRuntime().exec("/usr/bin/env");
    try {
    process.waitFor();
    if (process.exitValue() != 0) {
    return "Process exited with non-zero status";
    catch (InterruptedException intexc) {
    return "ERROR: "+intexc.getMessage();
    BufferedReader br1 = new BufferedReader(new InputStreamReader(process.getInputStream()));
    // blah, blah, blah, code to parse input from process
    // end
    The problem that I am having is that the class crashes whenever it is run. I have substituted 'env' for a number of other commands and these work ok which makes me suspect that there is some percularity with the 'env' program. Also, the code appears to halt on the 'exec' so it is nothing to do with the reading of input, it is the actual execution of the command that it causing the problem.
    Does anyone have any experience of using 'env' in this way under Solaris or has anyone managed to develop a similar class? Any help greatly appreciated.
    Cheers,
    Jon.

    Found a solution to this in the bug database.
    Bug ID: 4098442

  • GetRuntime().exec() hangs reading Linux stdin

    Hi All,
    First, my apologies if I’m in the wrong forum and would appreciate directions.
    I am having trouble getting the process to accept input from stdin. Commands that just write to stdout and/or stderr work fine. Each buffered stream has its own thread. I have even appended a <cr> to the input text but to no avail. For example, this script hangs on the read (even adding a sleep before the read is no help); but runs when hardcoding x and commenting out the read.
    abbrvd
    getRunTime().exec(“test.src”)
    proc.getOutputStream().write(“Hello World”) <expected in stdout>
    test.src
    #!/bin/bash
    read x
    /bin/echo $x
    Any help would be greatly appreciated.
    Thanks in advance.

    Easy translation for the ones who don't like hyperlinks:
    Don't forget to add the command shell in the exec() method
    (like command.com, /bin/sh, etc.).

  • Runtime.getRuntime().exec() and Garbage Collection

    I am programming a piece of software in both Java and C that has some strict real time requirements. Garbage collection, which pauses all threads in Java, sometimes causes loss of incoming data. In order to get around this, I am thinking to start another process using Runtime.getRuntime().exec("c_program") and using interprocess controls (in a UNIX environment) to retrieve data from the new process.
    My only worry is that the Process created by the above call would be a child process of whatever JVM thread created it, (as far as I understand, the JVM implementation in Unix uses multiple processes) and would also be paused when garbage collection occurs. Does anyone know the implementation of the exec functionality and the JVM well enough to say that this will or will not happen?
    Thanks in advance,
    Benjamin

    You're going to create a whole new process? I don't
    know what a "child process" means, but Runtime.exec()
    gets the operating system to produce an entirely new
    process, outside the JVM. However if it produces
    output on stdout or stderr, you're going to have
    threads in your JVM that read that output, otherwise
    that process will hang.
    Why is your idea better than just calling the C
    program via JNI?Thank you both for your replies. My plan was to create a whole new process, yes. In UNIX, a process C is created by another process P using fork() or the exec() family. Process P is then the parent of process C, and process C is the child of Process P. P has an amount of control over C since it can send various signals to pause, kill, etc to C.
    My concern was that the JVM implementation would use these signals to implement the pause of all threads before garbage collecting. If it did, it may also pause the Process that it spawned from the Runtime.exec() call. Pausing my C program in this manner would cause the loss of data I was trying to avoid in the first place.
    My plan for the new process was not to produce anything on stdout or stderr, but to pass data back to the JVM using ipc (interprocess communication) resources of UNIX. I would have to use the JNI to access these resources.
    The whole reason for wanting to do this is to avoid the pause during garbage collection that all Java Threads experience. If I were just to call the C program through the JNI with a normal Java Thread as I think you were suggesting, this Java Thread would still be paused during garbage collection.
    To the second reply about RTSJ, I had heard about this but couldn't find info about it! Thanks for the link. I'm checking it out at the moment. The java runtime must be considerably different for the specifications I see that they guarantee.
    Again, thanks for the replies,
    Benjamin

  • Inconsistent exit code from Runtime.getRuntime().exec

    I'm getting non-deterministic behavior from a call to a native process. Here is the code:
    public class Test {
    public static void main (String[] pArgs) {
    try {
    String cmd[] = { "cmp", "-s",
    pArgs[0],
    pArgs[1] };
    System.err.println("running command: ");
    Process p = Runtime.getRuntime().exec(cmd);
    System.err.println("getting exitcode...");
    int exitcode = p.waitFor();
    System.err.println(exitcode);
    System.err.println(p.exitValue());
    } catch(Exception e) {
    System.err.println("Caught exception while executing cmd");
    e.printStackTrace();
    And here is the output:
    bock@homeruns[~/work/index]10:08> java Test output output.old
    running command:
    getting exitcode...
    0
    0
    bock@homeruns[~/work/index]10:08> java Test output output.old
    running command:
    getting exitcode...
    1
    1
    bock@homeruns[~/work/index]10:08> java Test output output.old
    running command:
    getting exitcode...
    0
    0
    they should all be 1's because the files are different. when i run it on the command line i get:
    bock@homeruns[~/work/index]10:13> cmp -s output output.old ; echo $?
    1
    any help would definitely be appreciated!
    thanks,
    roger

    thanks for the link. i read through it but it doesn't seem to address why the exit code would be inconsistently reported. the other problems described by that link don't seem to apply to this case because i have not experienced hanging and there is no standard input, standard output, or standard error associated with "cmp -s" - all it does is return the appropriate exit code.
    should i be reporting this as a bug to sun? up till recently i've been assuming it was a problem with my code but now i'm not so sure...

  • Runtime.getRuntime().exec(...) problems and exit codes

    Hi,
    I am trying to launch an application 4 times with different arguments from a Java app. I have tried doing it sequentially and in four different threads, but the results are the same: sometimes the 4 of them are properly launched, sometimes (the most of the times) only 3 are launched and sometimes only 2. I have tried with cmd and cmdarray[] as parameters for exec but the results are the same.
    This is one of the four threads I use:
    Runnable r1 = new Runnable(){
                        public void run(){
                             String ecgCommand = "./flute -S -m:" + Config.ECGS_FLUTE_IP + " -p:" + Config.ECGS_FLUTE_PORT + " -F:" + Config.ECGS + " -r:" + Config.ECGS_FLUTE_RATE + " -C";
                             System.out.println(ecgCommand);
                             InputStream ecgsStream = null;
                             InputStreamReader isr = null;
                             BufferedReader br = null;
                             try{
                                  ecgsProcess = Runtime.getRuntime().exec(ecgCommand, null, new File(Config.HOME_PATH + Config.FLUTE_PATH));
                                  String line;
                                  ecgsStream = ecgsProcess.getInputStream();
                                  isr = new InputStreamReader(ecgsStream);
                                  br = new BufferedReader(isr);
                                  StyledDocument styleDoc = mm.ecgFluteMessages.getStyledDocument();
                                  Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
                                  while((line = br.readLine()) != null && running){
                                       if(styleDoc.getLength() > 25000)     mm.ecgFluteMessages.setText("");
                                       styleDoc.insertString(styleDoc.getLength(), line+ "\n", def);
                                       mm.ecgFluteMessages.setCaretPosition(mm.ecgFluteMessages.getDocument().getLength());
                                  System.out.println(ecgsProcess.waitFor());
                             }catch(Exception e){
                                  try {
                                       br.close();
                                       isr.close();
                                       ecgsStream.close();
                                  } catch (Exception e1) {
                                       e.printStackTrace();
                   new Thread(r1).start();Adding a Thread.sleep between runnables doesn't have any effect.
    In addition, those processes that are not properly launched return an exit value of 255. I have searched for its meaning but I have found nothing. Could anybody tell me where can I find a list of the JVM exit codes in order to guess what is happening?
    Can anybody help me with this issue? Help is much appreciated.
    Thanks a lot

    I have been looking for it but it seems it has not any exit code list or any documentation regarding this. Anyway, I think 255 is a JVM error code (the last one, errors are numbered in modulo 256) which means that the error has nothing to do with JVM but with the application execution (flute in my case).
    I have added a prompt for the errorStream and I have this message for the 255 exited programs:
    not well-formed (invalid token) at line 15+
    And the four commands are like this:
    *./flute -S -m:239.255.255.253 -p:60102 -F:./ecgs -r:150 -C*
    *./flute -S -m:239.255.255.252 -p:60103 -F:./ads -r:150 -C*
    *./flute -S -m:239.255.255.251 -p:60104 -F:./pushvod -r:50 -C*
    *./flute -S -m:239.255.255.250 -p:60105 -F:./banners -r:150 -C*
    So, as the process is sometimes initialized properly and others it is not, it seems that there is a problem with the tokenizing of the command not happening always. As I have tried it with a single command line and with an array of command strings (the first for "./flute" and the followings for each argument) with the same results I can't understand why is this problem happening sometimes. Happening always would help me in giving a clue but that's not the case.
    Any idea? Thanks a lot.
    Edited by: dulceangustia on Apr 3, 2008 3:41 AM

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

  • GetRuntime().exec problem

    I am trying to set a password for a user on a linux box but getRuntime().exec won't cooperate. I have researched this topic to death and haven't been able to find any solutions. I've rewritten the exec() and code several different ways and get no reponse or error message except when trying to use a pipe in the command, which is basically useless because I can't find any listing of what the error codes mean.
    In code previous to this the user is successfully added. This code tries to set the password. Under linux the system should prompt for the new password twice once the passwd command is executed. I read the input and error streams and get nothing. Depending on the way its coded the system either appears to hang (waiting on input?) or the waitFor() returns an error.
    Thanks for helping,
    Bob
    <PRE>
    try {
    proc = Runtime.getRuntime().exec("passwd " + this.usersName );
    InputStream istr = proc.getInputStream();
    InputStream estr = proc.getErrorStream();
    BufferedReader br = new BufferedReader(new InputStreamReader(istr));
    BufferedReader er = new BufferedReader(new InputStreamReader(estr));
    OutputStream output = proc.getOutputStream();
    PrintWriter outputWriter = new PrintWriter ( new OutputStreamWriter(output));
    // Get streams, write password
    String str;
    while ((str = er.readLine()) != null)
    logger.debug(str);
    while ((str = br.readLine()) != null)
    logger.debug(str);
    outputWriter.println(newpasswd);
    // Get streams, write password again
    while ((str = er.readLine()) != null)
    logger.debug(str);
    while ((str = br.readLine()) != null)
    logger.debug(str);
    outputWriter.println(newpasswd);
    if (proc.waitFor() != 0) {
    logger.error("Error setting password)");
    error = true;
    return false;}
    } catch(InterruptedException ex) {
    logger.error("Exception interrupted");
    } catch(IOException e) {
    logger.error("IOException error setting password.");
    error = true;
    return false; }
    </PRE>

    I saw running of different threads at http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html but thought it was a bit of overkill for a simple procedure.
    I was about to give up on this because the waitFor() would never exit.I used output.flush(), but apparently the process doesn't close until the output stream is closed. Another strange thing is half the input comes over the error stream and half over the output stream.Not for me to worry about because my problem is solved. The Thread.wait() seems to be important otherwise I get a conversation error.
    I only point this out so that later when someone else is looking it may be a bit easier than it was for me. People tend not to post a solution when they finally find the answer they are looking for. I searched, and though there were a lot of questions relating to this exact problem, nobody posted anything they found out.
    One of my clients blessed me this morning, so it must have been divine inspiration that lead me to the right combination that finally worked. The first waitfor() and flush() appear to be necessary. The second waitfor() is necessary but I didn't check the flush(). I doubt it is necessary, but what the heck, it works.
    Here is my final code that does work.
      Process proc = null;
      try {
        proc = Runtime.getRuntime().exec("/usr/bin/passwd " + this.usersName );
        OutputStream output = proc.getOutputStream();
        PrintWriter outputWriter = new PrintWriter(new OutputStreamWriter(output));
        // Get the messages
        StreamGobbler eg = new StreamGobbler(proc.getErrorStream(), "ERROR");           
        StreamGobbler og = new StreamGobbler(proc.getInputStream(), "OUTPUT");
        eg.start();
        og.start();
        Thread.sleep(500);
        outputWriter.println(newpasswd);
        outputWriter.flush();
        Thread.sleep(500);
        outputWriter.println(newpasswd);
        outputWriter.flush();
        outputWriter.close();
        if (proc.waitFor() != 0) {
          logger.error("Error setting password)");
          error = true; }
        } catch(InterruptedException ex) {
          logger.error("Exception interrupted");
        } catch(IOException e) {
          logger.error("IOException error setting password.");
          error = true; }
    class StreamGobbler extends Thread {
        InputStream is;
        String type;
        StreamGobbler(InputStream is, String type)
            this.is = is;
            this.type = type;
        public void run()
            try
                InputStreamReader isr = new InputStreamReader(is);
                BufferedReader br = new BufferedReader(isr);
                String line=null;
                while ( (line = br.readLine()) != null)
                   logger.debug(type + ">" + line);   
                } catch (IOException ioe)
                    ioe.printStackTrace(); 
        }

  • GetRuntime().exec(keytool) stucks up

    Hi,
    When I use keytool command with all parameters in Runtime.getRuntime().exec(my keytool command), sometimes it workss but mostly (90%), it stucks. What can be the problem exactly? The exact code is as follows:
    String command="keytool -dname=.... ";
    try {               
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec(command);
    InputStream stderr = proc.getErrorStream();
    InputStreamReader isr = new InputStreamReader(stderr);
    BufferedReader br = new BufferedReader(isr);
    String line = null;
    while ( (line = br.readLine()) != null)
    System.out.println(line);
    int exitVal = proc.waitFor();
    System.out.println("Process exitValue: " + exitVal);      
    }catch(Exception e) {          
    System.out.println(e.getMessage());
    }

    try using sun.security.tools.KeyTool or start a new Thread to execute that command

Maybe you are looking for

  • Reaction as pdf instead of an an html overview

    I am using AdobeForms for receiving forms from different sales agents. Everytime they fill in a form, I receive an e-mail with an overview of what they have filled in. However, this is sort of a html summary of what they have filled in. I would like

  • Blank DVDs rejected? help

    today i tried to put a DVD into my mac (powerbook G4 15") but after a couple of spins and some wierd noises it just got rejected and shot out. there is no error messages nothing. then i tried to use a cd which worked fine itunes popped up asking if i

  • '\n' and other notations in string concatonations!

    Can anyone tell me what the notation for tab is in string concatonations. The only one I know is '\n' for new line. I have looked for a list of these in many places, but as yet I'm unsuccessful. Thanks in advace, murrayjr.

  • Duplicate song titles

    Why am i getting duplicate song titles [ up to 4 ] in my music library when I upload my CD's

  • I can't open Pages, why not?

    I downloaded Yosemite OS and now I can't open a document in pages.  It keeps telling me to upgrade Pages.  I click on it to upgrade and it wants me to pay $19.99.  I don't understand this and I must have that file open as it contains all my new house