How to execute completely independent application from Java. Like independent process

邮差的信 提交于 2020-01-15 03:50:09

问题


I have one main application which launch two other process's, i just need to launch them as an independent process. like running them-self without using or sharing my main application launcher process memory or cpu.

But when i launch it like this TWO other process do not get executed (well they create TWO new process but not fictional), unless i kill the main process. My plan is to execute it under windows just like THREE command prompt where it execute THREE application.

How do i resolve it so that THREE execution run completely alone?

/*This is Process 1 itself*/
try {

  if (myStock.getOs().equals("Linux")) 
  {
    Runtime.getRuntime().exec("java -cp /var/dist/test.jar main.main");        
    Runtime.getRuntime().exec("java -cp /var/dist/test.jar www.webserver_starter");

  } else {

    /*Windows 7 only*/
    String WindowsTemp = System.getenv("MY") + "\\";
    /*This is Process 2*/
    Runtime.getRuntime().exec("java -cp " + WindowsTemp + "dist\\test.jar main.main");        
    /*This is Process 3*/
    Runtime.getRuntime().exec(
        "java -cp " + WindowsTemp + "dist\\test.jar www.webserver_starter");
  }

} catch(Exception e) {
  System.out.println(e);
}

回答1:


For Windows use cmd /c start ... where '...' is the command you would like to invoke.

Runtime.getRuntime().exec("cmd /c start java -cp /var/dist/test.jar main.main")

For Linux add & at the end of command to start a daemon process.



来源:https://stackoverflow.com/questions/8729523/how-to-execute-completely-independent-application-from-java-like-independent-pr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!