Runtime.exec() causes app to hang

Hello all, I'm having an issue with the Runtime.exec() and I'm hoping someone in the forum can shed some light on it for me.
My application currently includes the capability for my end users to run a variety of reports, all of which are written in SQR (BRIO reporting language). Since my application is in Java ( and all the reports were written for a previous application), I use the Runtime.exec() call to launch the SQR viewer application. The problem I'm having is this: When I run the code below in my development environment (using a front end framework from Oracle (JDeveloper)), everything works fine. When I deploy my application to a jar file, the application runs fine until the code below is called. At this point the application hangs terribly and my CPU usage is maxed out by my app. The process for the report is created but is unable to garner the necessary resources to run because my application is using them all. If I kill my application, the report process then runs as expected.
Why would the same code run fine in development but not when deployed to a jar file?
The following is the code in question:
    try {
      Runtime rt = Runtime.getRuntime();
      Process proc = rt.exec(sDrive + "\\SQR6\\SQRW " + sDrive + "\\SQR6\\REPORTS\\" + repName + ".SQT " + sConn + " -RT -FC:\\SPL\\ -C -ZIV");
      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();
    catch (Throwable ie)
      ie.printStackTrace();
    }    All thoughts and suggestions are welcomed.
Thanx in advance,
eribs4e

So you either tried adding a reader for stdout, or you're sure that nothing is produced on stdout? And you're sure it's not expecting anything on stdin?
You say your app runs fine up to that code, and then eats all the CPU right? Sounds like a spin lock. One possibility is that it's something like this: br = bufferedReaderForStdOut;
while ( (line = br.readLine()) != null)
        System.out.println(line);
while ((line = br.readLine() == null); Not that I expect that you have precisely that in your code, but I suspect the problem may actually be a spin-lock that precedes the code you've posted. I don't see anything obviously wrong with what you have, so if there's a problem in your code, it's probably in what you haven't shown.

Similar Messages

  • Save as Photoshop PDF causes app to hang

    Every time I try to save a file as a PDF on Photoshop, the program hangs and I have to force quit eventually.  Oddly enough, it works fine the next time I try after restarting Photoshop, but it consitently hangs the first time every time.  So when I need to generate a PDF, and have to save in another format (Tiff) , save as PDF, let it hang, force quite, restart PS, open the Tiff file , then save as a PDF.
    ANyone else finding thsi issue?  Any suggestions?

    Hi, Brown
    it works fine the next time I try after restarting Photoshop, but it consitently hangs the first time every time.
    I am a little confused. Photoshop will hang after save tiff and then save PDF? Save PDF can only succssful at the first save after restart? Could you please provide detaied steps and a screen recording will be best, and send your steps, test files, OS info to: [email protected]? I will log a bug if necessary.
    Thanks,
    Ping

  • Bug - Fill Light slider causes app to hang

    Lightroom release v1.0
    When I slide the fill light slider to the right I get the hourglass and have to force quit the application.
    Using a Dell Insprion 9300 laptop, Pentium M chip 2.0 ghz, 1MB RAM

    Do you have an NVIDIA graphics chip in your laptop? If so, disable the nView tool and try again.
    Alexander.
    Canon EOS 400D (aka. XTi) • 20" iMac Intel • 12" PowerBook G4 • OS X 10.4 • LR 1 • PSE 4

  • 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.exec hangs even If I drain output.

    Hi Everyone,
    I'm trying to make a program that would give me access to a command line on a remote server. So what I'm trying to do is use Runtime.exec("cmd") to open a command line, then reading from it and printing to it normally.
    The problem is the same very common problem anyone using exec encounters: it hangs. The thing is, however, I do drain the input and error streams immediately, but it still hangs, and here's a curious thing:
    When I use a BufferedReader and use its readLine() method, it only manages to read the first two lines before it hangs, giving me an output such as this:
    +Microsoft Windows XP [Version 5.1.2600]+
    +(C) Copyright 1985-2001 Microsoft Corp.+
    Of course I placed the System.out.println inside the loop that reads lines, cause if I put it outside the loop, I don't get any output at all because the subprocess hangs before the loop is finished.
    Now if I don't use a buffer, and use the input's stream's read() method, it reads all the way through the output, but hangs at the end where it's supposed to read -1, and never reads it.
    I thought maybe I could bypass that, and break the loop at the last character in the output (the character '>'). Now while this works the first time, sending the output to the client like this:
    +Microsoft Windows XP [Version 5.1.2600]+
    +(C) Copyright 1985-2001 Microsoft Corp.+
    F:\eclipse workspace\RemCommand>
    However it doesn't work after that, when I try to type any command. I send my command to the subprocess normally using a PrintWriter, and then try to read the output, but that fails because apparently the subprocess is still stuck at the -1 from the previous read operation.
    I really don't know what the problem is, is it possible that the read possibly doesn't return -1 at all, maybe returns a different character to signify the end or something, and my loop keeps trying to read or what?
    I'm at my wits end.
    Any help?
    Thanks in advance.

    Here is the code again. Check the somehow improved detection of the default Windows prompt.
    Check the lines in comments that allow you to define your own, perhaps more reliable prompt.
    import java.io.*;
    import java.util.*;
    public class Cmd
      public static void main( String[] args ) throws Exception
        ProcessBuilder pb = new ProcessBuilder( "cmd" );
    //    Map<String, String> env = pb.environment();
    //    env.put( "PROMPT", ".,.,." );
        pb.redirectErrorStream( true );
        Process p = pb.start();
        InputStream is = p.getInputStream();
        OutputStream os = p.getOutputStream();
        PrintWriter pw = new PrintWriter( os, true );
        readToPrompt( is );
        pw.println( "dir" );
        readToPrompt( is );
        pw.println( "ipconfig" );
        readToPrompt( is );
        pw.println( "netstat" );
        readToPrompt( is );
      private static void readToPrompt( InputStream is ) throws IOException
        String s = "";
        for (;;)
          int i = is.read();
          if ( i < 0 )
            System.out.println();
            System.out.println( "EOF" );
            System.exit( 0 );
          s += new String( new byte[] { ( byte )i } ).charAt( 0 );
          if ( s.endsWith( "\r\n" ) )
            System.out.print( s );
            s = "";
    //      if ( s.equals( ".,.,." ) )
          if ( s.length() > 2 && s.charAt( 0 ) >= 'A' && s.charAt( 0 ) <= 'Z' && s.charAt( 1 ) == ':' && s.endsWith( ">" ) )
            System.out.print( s );
            break;
    }Edited by: baftos on Sep 10, 2008 11:27 AM

  • 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.exec() hangs with 1.4.1

    Hello altogether,
    I am trying to execute a command with Runtime.getRuntime.exec()
    I have already taken care of capturing the output and I observe that depending of the program I try to execute the process hangs.
    I am using JRE 1.4.1_02 under Redhat 7.2 with kernel 2.4.18-26
    Executing the same program under JRE 1.3.1 the program does not hang.
    Executing 'top -bn0q' hangs, executing 'ls -als' it hangs.
    Here is my sample code:
    <code>
    import java.io.*;
    public class Exec
    /** catches the output in a parallel thread */
    class StreamReader extends Thread
    String category = null;
    InputStream is;
    StreamReader(String category, InputStream is)
    this.category = category;
    this.is = is;
    public void run()
    try
    System.out.println(this.category+": reader runs");
    InputStreamReader isr = new InputStreamReader(this.is);
    BufferedReader br = new BufferedReader(isr);
    String line = null;
    while (br.ready() && (line = br.readLine())!=null)
    System.out.println(this.category+':'+line);
    catch (Exception e)
    e.printStackTrace();
    public void run(String[] cmd)
    StringBuffer outStrBuf = new StringBuffer();
    try
    Runtime rt = Runtime.getRuntime();
    System.out.println("got runtime");
    Process process = rt.exec(cmd);
    System.out.println("fired cmd");
    // any errors
    System.out.println("prepare error stream");
    StreamReader errSr = new StreamReader("ERR",process.getErrorStream());
    // any output
    System.out.println("prepare output stream");
    StreamReader outSr = new StreamReader("OUT",process.getInputStream());
    // start the readers to read
    System.out.println("start readers");
    errSr.start();
    outSr.start();
    System.out.println("waiting for process to end");
    process.waitFor(); //Waits for the subprocess to complete.
    catch (Exception e)
    System.err.println("Error while executing cmd: " + cmd);
    e.printStackTrace();
    System.out.println(outStrBuf);
         public static void main(String[] args)
    String [] cmd = {"top","-bn0q"};
    if (args.length >= 1)
    cmd = args;
    System.out.println(args[0]);
    Exec exec = new Exec();
    exec.run(cmd);
    </code>
    The output of java Exec is:
    [user]$ java Exec
    got runtime
    fired cmd
    prepare error stream
    prepare output stream
    start readers
    waiting for process to end
    OUT: reader runs
    ERR: reader runs
    ...and there it hangs. Interesting is, that when I use ls -als as command, I get the directory listing.
    Do you have any ideas what I am doing wrong? Is there any difference in the Runtime.exec() between 1.3 and 1.4 version?

    Unbelievable and what a shame. I was hacking 2 days on several variations of this problem and the solution and I finally found one difference:
    while (br.ready() && (line = br.readLine())!=null)
    I assume that when executing the command, the output streams are not ready and my Output gobbler threads end.
    ...however the command is still executing and starts to write its output. And as we all know this will overflow the buffer and the process hangs.
    So the final solution is:
    /** catches the output in a parallel thread */
    class StreamReader extends Thread
      String category = null;
      InputStream is;
      StreamReader(String category, InputStream is)
        this.category = category;
        this.is = is;
      public void run()
        try
          System.out.println(this.category+": reader runs");
          InputStreamReader isr = new InputStreamReader(this.is);
          BufferedReader br = new BufferedReader(isr);
          String line = null;
          while (/**br.ready() &&*/ (line = br.readLine())!=null)
            System.out.println(this.category+':'+line);
        catch (Exception e)
          e.printStackTrace();
    }So the only question that I have open: Why does this makes no problem with 1.3 but with 1.4 ?

  • Runtime.exec hang

    I used Runtime class to run a 3rd party exe. If I just called
    Runtime.exec("3rd.exe whatever"), 3rd.exe would run half way
    then hang. If I called Runtime.exec("start 3rd.exe whatever"),
    3rd.exe would run successfully. However, Runtime.getInputStream
    couldn't receive the output from 3rd.exe.
    Is any way I can get the output from 3rd.exe with "start 3rd.exe
    whatever"?

    Hi,KellanMom :
    I also experienced this problem.
    You should read sth from Process's inputStream,
    outputStream and errorStream.
    You can browse "http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html" to get details.
    Regards.
    Sunway

  • Runtime.exec() + getOutputStream() +write+me program=hang

    I'm trying to write to the standard input of an external prorgram by using Runtime.exec() and writing to the outputstream of the process it creates. I write to the standard in and then wait for that process to finish using waitFor() but it just hangs there. Is there something special to do before writing the data?
    There is nothing funky about my code, it's just basic stuff.
    OutputStream out =process.getOutputStream();
    out.write(data);
    out.flush();
    out.close();
    process.wairFor();

    Do you really know
    1. That the process got the data and processed it?
    2. That the process exited and you are still hanging?
    Sorry if I'm just stating the obvious, but is the other process perhaps waiting for an end-of-line or end-of-input?
    Finally, you didn't say what the other process technology is, but I've had some surprises when attempting to work between java and other technologies. Example: Other process was LEX, which uses a Windows flag to check for character or block input. Flag was set in a surprising manner when java was the source, and my LEX blocked forever.

  • Problem with runtime.exec().It hangs Up

    Hi all,
    I am having a problem with the runtime.exec method.I am trying to execute linux commands using this method.For most of the commands it works fine.But when i tried to change the user with the su command in linux my program hung up.So please help me to get around this.any help would be highly appreciable..
    I am pasting the code..
    <code>
    Process p=null;
    int ch=0;
    try
    System.out.println("Before executing command");
    String unlock_command="sh changeuser.sh";
    p = Runtime.getRuntime().exec(new String[] {"/bin/sh","-c","su tony"});
    InputStreamReader myIStreamReader = new InputStreamReader(p.getInputStream());
    while ((ch = myIStreamReader.read()) != -1)
    System.out.print((char)ch);
    p.waitFor();
    int p_exitvalue = p.exitValue();
    System.out.println("After executing the command and the exit value = "+p_exitvalue);
    p.destroy();
    catch (IOException anIOException)
    System.out.println(anIOException);
    catch(Exception e)
    e.printStackTrace();
    </code>
    Thanks
    HowRYou

    Hi sabre,
    What you have pointed out is right.But if i change the user as root then it will not ask for a password.Isn't it.Anyway thank you for giving your suggestions.Can yoiu help me more.Waiting for all of your help.I will try to swoitch between different users othere than root by giving the password.So just help me.

  • The Runtime.exec methods doesn't work well on Solaris ???

    I have two threads and I set the different running time.
    I use Runtime.exec to a run the command and use Process to get the process.
    It works properly in the windows2000 platform.
    However, when I transfer the platform to Solaris...and run the program...
    Two threads always at the same time....It is very wired....I always debug
    for 2 days....
    (at first I run "vmstat 1 2" command, later I change to "ls","rmdir"....etc,
    all of them don't work.....
    If I close the Runtime.exec..........Everything works well......)
    And I study the API. I found this message...
    The Runtime.exec methods may not work well for special processes on certain
    native platforms, such as native windowing processes, daemon processes,
    Win16/DOS processes on Win32, or shell scripts. The created subprocess does
    not have its own terminal or console.
    Could someone share her/his experience.....:(
    And if any other way I can run command inside java code instead of
    Runtime.exec.....???
    Please reply my mail to [email protected] I do appreciate your kindly &
    great help!!!!!!!!
    This is my code.......
    import java.io.*;
    import java.lang.*;
    import java.util.*;
    * <p>ServerThread1</p>
    * <p>??�X???��?�D???�X???, "Vmstat 1 2".</p>
    class ServerThread1 extends Thread{
    private ServerAgent Sa;
    public ServerThread1 (String Name, ServerAgent Sa){
    super(Name);
    this.Sa = Sa; file://Assign ServerAgent reference Sa
    public void run(){
    while(true){
    try{
    Thread.sleep(5000);
    catch (Exception e){
    System.out.println("ServerThread1 fails");
    System.out.println("Thread1 is running.");
    try {
    Runtime rt1 = Runtime.getRuntime();
    Process proc1 = rt1.exec("mkdir"); ------>If I close
    rt1.exec , two threads works seperately...........:(
    catch (Exception e) {
    System.out.println("Thread1 Error");
    class ServerThread2 extends Thread{
    private ServerAgent Sa;
    public ServerThread2 (String Name, ServerAgent Sa){
    super(Name);
    this.Sa = Sa;
    public void run(){
    while(true){
    try{
    Thread.sleep(15000);
    catch (Exception e){
    System.out.println("ServerThread2 fails");
    System.out.println("Thread2 is running.");
    try {
    Runtime rt2 = Runtime.getRuntime();
    Process proc2 = rt2.exec("vmstat 1 2"); ----->If I don't run
    the rt2.exe, two threads work seperately....
    catch (Exception e) {
    System.out.println("Thread2 Error");
    public class ServerAgent{
    private Vector v1 = new Vector();
    private Vector v2 = new Vector();
    private Hashtable currentData = new Hashtable();
    private static String startUpSwap = null;
    private static String startUpMem = null;
    public static void main(String[] arg) {
    ServerAgent s = new ServerAgent();
    ServerThread1 st1 = new ServerThread1("Thread1",s);
    ServerThread2 st2 = new ServerThread2("Thread2",s);
    st1.start();
    st2.start();

    If I close the Runtime.exec..........Everything works
    well......)You don't empty the output of the command, that blocks the process.
    A citation from
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    Why Runtime.exec() hangs
    The JDK's Javadoc documentation provides the answer to this question:
    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.
    Try out something like this:
    String s;
    try {
       Process myProcess =
       Runtime.getRuntime().exec("ls -l"));
       DataInputStream in = new DataInputStream(
              new BufferedInputStream(myProcess.getInputStream()));
        while ((s = in.readLine()) != null) {
            out.println(s);
    catch (IOException e) {
        out.println("Error: " + e);
    }Another source of trouble under Unix is not having the correct permission for that user that executes the Java VM, which will be the permissions for the spawned subprocess. But this probably not the case, as you see something after exit.
    Regards,
    Marc

  • Copying in Preview causes app to crash

    All of a sudden copying in Preview causes the app to hang briefly then exit. Anyone else having this problem and any ideas on a workaround for copying .pdf text?

    It depends on how the exe deals with the arguments. Some do honor escape characters, some not.....
    Afaik, there is no difference regarding the System Exec in development environment vs. exe. But it is possible, that these are executed using different user rights?
    Norbert
    CEO: What exactly is stopping us from doing this?
    Expert: Geometry
    Marketing Manager: Just ignore it.

  • Running interactive command with Runtime.exec

    I'm trying to run a command via the Runtime.exec interface.
    Occasionally, the command needs to prompt for additional information. The response depends on the specific configuration, however, the command returns a list of options and then waits for a response.
    However, when the command waits for the response, my Java app hangs.
    After I call Runtime.exec, I create 2 threads to consume the contents of stderr and stdout. I then start them and call proc.waitFor()
    I would expect to see the output of the command in the stdout stream even though the command hasn't exited. I had hoped to parse the output to determine the necessary response. However, the calls to read the contents of the stdout and stderr streams block and I never see any output.
    How can I get access to the contents of those streams while the command is still running? Is this supported through the Runtime.exec interface?
    Thanks,
    Shawn

    This article should help:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • Process.waitFor() causes program to hang!

    I've successfully created a Process and run it using Runtime's exec(String path), and the kinds of processes I've successfully run have included Winzip, a WS_FTP Pro script, and a regular .bat file. I've also successfully called waitFor() on these processes, but in this particular case I'm calling a program that takes a file I give it as a parameter and merges its data into a database. I've been doing this procedure for a while (either from a command line or in a .bat file), but now I need to call it from my Java code. Preferably I'd like to waitFor() the process each time because I need to make sure all the files are merged in chronological order. My current test case only uses ONE file, but in reality there will be several. With one file, I can run the program and it appears to run fine (and it runs fast--like maybe a second or two at most), but whenever I call the following line it hangs indefinitely (I've never seen it terminate, even after several minutes):
    focusProcess.waitFor();
    When I just execute that program by itself by calling a .bat file with a hardcoded filename, I get standard output back from the program I'm calling. I'd like to see this output when I run my Java program and it appears to run fine, because I have no way if it IS running correctly! So, I added the following:
    BufferedInputStream bis = new BufferedInputStream(focusProcess.getInputStream());
    StringBuffer sb = new StringBuffer();
    int c;
    while((c=bis.read()) != -1) {   
    sb.append(c);
    bis.close();
    I'm not sure if this is the right way to monitor that InputStream that I get from the process, and even if that InputStream is going to give me the standard output from that the process normally writes to the terminal. All I do know is that again, the program seems to hang indefinitely, and I guess it has to do with the fact that maybe this process isn't notifying me that it's terminated, and so I'm still waiting for the rest of that InputStream. And yes, I HAVE tried both of these situations together AND separately (so I know that both pieces of code cause the program to hang).
    Any ideas would be much appreciated!

    Paying attention to the standard output from the running process is good for debugging (and reporting program progression, if necessary) but probably doesn't contribute to the problem you are seeing. The standard input to the process, however, is a different story. If the process you have Runtime.exec'd is waiting for something on stdin, then the OS will block on behalf of the program that is blocking for input and never terminate!
    Try running the exec'd command from the command-line and see if it needs any input (i.e. you have to press a key, or enter, or send EOF) for the program to complete. If this is the case then your Java program must supply that process with the appropriate input or it will just hang.
    As for printing the output from a process... here's a quick proof of concept:
    import java.io.*;
    public class Exec {
        public static void main(String args[]) throws Exception {
            // Make sure we've got something to exec.
            if ( args == null || args.length < 1 ) {
                System.out.println("Usage: java Exec COMMAND [ARGS...]");
                System.exit(1);
            // Run the process and print the output.
            Process p = Runtime.getRuntime().exec(args);
            BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String line;
            while ( (line=in.readLine()) != null ) {
                System.out.println("EXEC: "+line);
    }Hope this helps!
    -mike

  • Launching another VM instance using Runtime.exec()

    Hi,
    I have two separate Swing applications, say A and B. I need to launch B from A using Runtime.exec() - essentially I am launching another VM instance from one VM. I am encountering strange problems - B's main window comes up, but GUI doesn't update; sometimes B comes up and GUI updates, but huge memory leaks happen. All the problems with B go away once A is shut down. It almost looks like both the instances of VM are sharing (or competing for) the event thread. Any comments will be of great help. Thanks.
    note: There is no problem launching B if A is a console java application (i.e. no Swing GUI).

    I have recently had the same problem, especially with the part where it seems like the two applications are sharing or competing for the same event thread. Sometimes my application B hangs like it is stuck waiting for an event. Sometimes I can get it to unhang by moving the app window around or minimizing it. If it does break free, all the queued events occur in rapid succession. Anybody have any clue what's going on here? It's pretty annoying.

Maybe you are looking for

  • Permissions can't be repaired

    I'm having some apparently random kernel panics which I'm trying to track down. Attempts at permissions repair (using both Apple Disk Utility and Diskwarrior) give me a list of the following permissions that "have been modified and will not be repair

  • IPhone 2.0: Sync crashes and continues to run simultaneously???

    So, when I sync my iPhone, I get the "battery and Sync in Progress" screen, and iTunes says it is syncing. But then the phone goes back to the home screen as if the Sync is complete (far too soon, and without going through all the steps), while iTune

  • I recieve email, but cant send out tells me my password is wrong

    i have the same password on my desc top and my iphone emails.  today i cant email anything out, it tells me my user name or password is wrong

  • TS3694 unknown error 2001

    The battery in my iPhone 4 drained really fast today. When I plugged it in I just got the itunes logo on the screen. When I try to restore the phone now i get unknown error 2001 Anyone else had this problem?

  • Apple tv keeps telling me that my password or atv id is incorrect

    when I try to watch something on ATV and try to input my AID and Password it keeps telling me that the password or appleID is incorrect. How do I fix this?