Starting java .app in java via Runtime.getRuntime().exec crashes with 'Program quit unexpectedly'

615 Views Asked by At

I want to start an .app Application in java on a Mac OS X 10.7.5 with the following code:

Runtime.getRuntime().exec(new String[] { "/usr/bin/open",  filename });

The filename contains the physical path and the filename.

If I start the filename double clicking it on the MAC file manager Finder, everything works fine.

If I execute the code line showed above I get the well known error message "TeamViewerQS quit unexpectedly Click reopen to open the application again..."

If I click the button "Reopen" the app will start without any problems.

So how can I avoid this disturbing error message?

If you need any further information about this issue please let me know. Thank you.


2013-10-04: Ok, now I had time to follow this task again and here comes the asked working piece of code (StreamGobbler is the same as described in "When Runtime.exec() won't"):

/**
* Start the teamviewer application on a mac. 
* 
* @param filename Full physical path and filename to be started
* @throws IOException
*/

protected void startTeamViewerOnMac(String filename) throws Throwable{
    String[] cmd = new String[] { "/usr/bin/open",  filename };
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec(cmd);

    // Creation of the stout and errout handler
    StreamGobbler errorGobbler = new 
            StreamGobbler(proc.getErrorStream(), "TeamViewer start Error");
    StreamGobbler outputGobbler = new 
            StreamGobbler(proc.getInputStream(), "TeamViewer start STDOUT");
    // Start them
    errorGobbler.start();
    outputGobbler.start();

    int exitVal = proc.waitFor();
    JLog.submit(this, "ExitValue:" + exitVal, Level.WARN);
} // end of startTeamViewerOnMac

Output of the logger:

  04.10.2013 14:38:02 WARN  [main.frame.PdfHelpPanelSetlog->startTeamViewerOnMac] ExitValue:0

Therefore no STDOUT or ERROUT were generated before or after the Error screen.


I also tried to use the complete path to the binary. => Won't work.


And I've also tried this:

protected void startTeamViewerOnMac(String filename) throws Throwable {

    ProcessBuilder pb = new ProcessBuilder("/usr/bin/open", filename);
    Process proc = pb.start();

    // Creation of the stout and errout handler
    StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "TeamViewer start Error");
    StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "TeamViewer start STDOUT");
    // Start them
    errorGobbler.start();
    outputGobbler.start();

    int exitVal = proc.waitFor();
    JLog.submit(this, "ExitValue:" + exitVal, Level.DEBUG);
}

=> The same error message occurs

0

There are 0 best solutions below