I have written an application which simply executes java -jar. I want the starter application to exit immediately after executing CreateProcessA.
LPSTR _cmdupdate = const_cast<char *> (cmdupdate.c_str());
STARTUPINFO info = {sizeof (info)};
ZeroMemory(&info,sizeof(info));
info.cb=sizeof(info);
PROCESS_INFORMATION processInfo;
ZeroMemory(&processInfo,sizeof(processInfo));
CreateProcessA(TEXT(java_exe.c_str()), _cmdupdate, NULL, NULL, false, 0, NULL, TEXT("bin"), &info, &processInfo);
CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread);
exit(0);
If I’am executing this via IDE (Netbeans 7) everything works fine: java continues running while the starter terminates.
If I’am running the same exe by double clicking on it: java starts up the jar, but the starter waits for the java process to exit.
So what’s the difference to CreateProcess when running via IDE vs. running standalone?
The Java interpreter is a console process. Chances are that your program is a console process too, so Java inherits and shares your console. That’s why your process seems to wait for the Java to finish. It actually does not, just the console stands there.
When you run your program from the IDE, it probably handles the console in a special way and makes it disappear when your program finishes. Or maybe it redirects the output and hides the console in the first place.
Solution: Use some of the flags defined here to handle the console of the new process. Try
CREATE_NEW_CONSOLEorDETACHED_PROCESSor maybeCREATE_NO_WINDOW.