问题
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