如何从Java执行完全独立的应用程序.像独立程序 [英] How to execute completely independent application from Java. Like independent process
问题描述
我有一个可以启动其他两个进程的主应用程序,我只需要将它们作为一个独立的进程启动即可.就像自己运行它们而无需使用或共享我的主应用程序启动器进程内存或CPU.
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.
但是当我像这样启动它时,不会执行两个其他进程(好吧,他们创建了两个新进程,但不是虚构的),除非我杀死了主进程.我的计划是在Windows下执行它,就像执行三个应用程序的三个命令提示符一样.
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);
}
推荐答案
对于 Windows ,请使用cmd /c start ...
,其中'...'
是您要调用的命令.
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")
对于 Linux ,在命令末尾添加&
以启动守护进程.
For Linux add &
at the end of command to start a daemon process.
这篇关于如何从Java执行完全独立的应用程序.像独立程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!