English 中文(简体)
在目前 con光窗口中建立新的程序
原标题:Create a new process in current console window

我有 Java申请,例如需要重新启动(但还需要启动其他进程)。 目前,通过关闭目前的申请,然后利用ShutdownHook和一个工序开始一个新案例。

我现在的问题是,新进程在某种背景下运作,没有自己的光辉窗口。 在窗户机器上,可以使用新的黄色窗口。

cmd /c start "windowtitle" java -jar myApp.jar

但是,这产生了2个进程: cm碎过程和 j进程始于启动。 举例来说,这使得启动进程的 st和梯子无法走下去,因为我们只能把这些溪流用于细化进程,而不是从开始指挥开始。

The very best solution for me would be to reuse the current console window for the new process but this seems somehow impossible to achieve as i did not find any information on how to do this. Additionally I would appreciate a solution which works on Unix machines.

问题回答

Seems, you owe to use small console program-starter for java. It must start java and immediately exit.

#include <windows.h>
#include <tchar.h>

int main(int argc, char** argv)
{
  STARTUPINFO si = {sizeof(si)};
  PROCESS_INFORMATION pi = {};
  CreateProcess(NULL,_T("java -jar myApp.jar"),0,0,0,NORMAL_PRIORITY_CLASS,0,0,&si,&pi);
  return 0;
}

我不知道这是否是你重新思考的,但会有所帮助。

List<String> command = Arrays.asList("java", "-jar", "myApp.jar");
ProcessBuilder builder = new ProcessBuilder(command);
builder.redirectErrorStream(true);
Process process = builder.start();

InputStream is = process.getInputStream();
final InputStreamReader isr = new InputStreamReader(is);
final BufferedReader br = new BufferedReader(isr);

String line = null;
while ((line = br.getLine()) != null) {
    System.out.println("child process: " + line);
}

process.waitFor();

The builder.redirectErrorStream (true); will redirect thepinderr to setdout, and the loop will written the ocdout of the child process to the set out of You main application. 不要忘记<条码> 渔获量。 <代码>Streams和Buffers





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签