0

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

  • 1) Read (and implement) *all* the recommendations of [When Runtime.exec() won't](http://www.javaworld.com/jw-12-2000/jw-1229-traps.html). That might solve the problem. If not, it should provide more information as to the reason it failed. Then ignore that it refers to `exec` and build the `Process` using a `ProcessBuilder`. Also break a `String arg` into `String[] args` to account for arguments which themselves contain spaces. 2) For better help sooner, post an [SSCCE](http://sscce.org/). – Andrew Thompson Sep 05 '13 at 11:26
  • Hi, I've read the recomendations of When runtime.exec() won't, but none of the hints seems to fit to my problem. No Exception or anything is thrown by my program. I've allready tried the ProcessBuilder with the same result. The break into `String[]` is allready done (see my example above). If you want I can provide the crash protocol so you can see what is going on on OS. – user2750283 Sep 06 '13 at 07:08
  • Here goes the fist part of the errror protocol: Process: TeamViewerQS [451] Path: /Users/USER/*/TeamViewerQS.app/Contents/MacOS/TeamViewerQS Identifier: com.teamviewer.TeamViewerQS Version: 6.0.11879 QS (1) Code Type: X86 (Native) Parent Process: launchd [374] Date/Time: 2013-09-05 09:30:17.662 +0200 OS Version: Mac OS X 10.7.5 (11G63b) Anonymous UUID: 82B2866D-CBD4-4FFE-9147-54A106809C59 Crashed Thread: 4 Exception Type: EXC_BAD_ACCESS (SIGBUS) Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000000000038 – user2750283 Sep 06 '13 at 07:14
  • *"none of the hints seems to fit to my problem."* You might want to show a code snippet or SSCCE that supports you both understand and implemented those hints. The `ProcessBuilder` makes them easier to implement. – Andrew Thompson Sep 06 '13 at 07:50
  • Please have a look the update of the problem description. Thanks. – user2750283 Oct 04 '13 at 13:04

0 Answers0