0

I have been trying to find an answer to this question for quite a while an I am not having any luck. Below I have an example of a simple program that is supposed to open Skype on my Mac. Everything compiles and runs fine, but as soon as Skype opens, it closes itself. How do I make sure it keeps itself open?

public class program{
    public static void main(String[] args) throws Exception{
        Process p = Runtime.getRuntime().exec(
     new String[]{"open","/Applications/Skype.app"}
     );
    }
}
glawley
  • 1
  • 1
  • 1. Consider using a `ProcessBuilder` instead or `Runtime` directly; 2. Consume the output of the process in order to check if it's outputting any error states; 3. Look at the return of `Process#exitValue` to see if it's returning an error state – MadProgrammer Feb 21 '18 at 08:15
  • That's because you're spawning a new process as a child of the main java process. As soon as your java program ends, it kills its child. Have you tried [`p.waitFor()`](https://stackoverflow.com/questions/17972380/wait-for-process-to-finish-before-proceeding-in-java)? – Oneiros Feb 21 '18 at 08:22
  • You may also be interested in spawning a new process completely indipendent from the java one, [have a look here](https://stackoverflow.com/questions/931536/how-do-i-launch-a-completely-independent-process-from-a-java-program/931579) – Oneiros Feb 21 '18 at 08:26

0 Answers0