Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: how to execute a process which is not attached to a Windows console?

Both, Runtime.exec() as well as ProcessBuilder seem to attach a console to the started process. On Windows 7, one can see a conhost.exe popping up in the Task Manager. My problem is now that the C process I'm trying to start performs following test to determine whether it has a console window to which it can issue prompts:

HANDLE cons = CreateFile("CONOUT$", GENERIC_WRITE,
            FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
            FILE_ATTRIBUTE_NORMAL, NULL);

if (cons != INVALID_HANDLE_VALUE) {
   // Prompt user; this makes my application hang
}

Is it possible with Java to start the C process in a way that upper test fails in order to avoid the prompt?

like image 580
mstrap Avatar asked Sep 23 '11 19:09

mstrap


1 Answers

At least on OpenJDK 6, CreateProcess is being called with CREATE_NO_WINDOW. I would imagine that the Sun JDK's code is pretty similar. This makes me wonder if something else is causing that console to be present. Have you tried running your program with javaw.exe instead of java.exe?

Thinking outside of the box, maybe JGit is a better way to solve your particular problem.

like image 93
Stop Harming the Community Avatar answered Nov 19 '22 16:11

Stop Harming the Community