apparently running java on Windows using this:
CreateProcess( TEXT("..\\jre\\bin\\java.exe"), ...
Also produces the same error, despite running java.exe.
I cannot reproduce this behaviour. For me, using this program:
#include <stdio.h>
#include <Windows.h>
int main(int argc, char** argv) {
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
if (!CreateProcess(TEXT("any\\relative\\or\\absolute\\path\\to\\java.exe"),
TEXT("any\\relative\\or\\absolute\\path\\to\\java.exe -jar the.jar"), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) {
fprintf(stderr, "%s\n", "ERROR!");
fflush(stderr);
return 1;
}
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return 0;
}
runs just fine. Of course, leaving out the ".exe" extension will not work since CreateProcess() is no shell/command interpreter like cmd.
Also take note that the program name must be repeated in the second argument to CreateProcess() because of conventions on how to call C programs, as mentioned in the documentation of
CreateProcess, or otherwise the Java launcher will not see the first command line argument.
EDIT: Changing the "java.exe" to "java" in the _second_ argument of the CreateProcess() call results in the known error. That's probably what you were using/experiencing.
EDIT2: It seems that the Nvidia driver does not like when the first command line argument of the process (argv[0] in C-speak) does not exactly match the last path-segment of the exe module name including the '.exe' file extension the process was started with. Practically with any other application it is possible to specify argv[0] as anything you'd like, such as with this call:
CreateProcess(TEXT("path\\to\\java.exe"), TEXT("whatever -jar the.jar"), ...
This works with any non-OpenGL, non-Direct3D Java application, because the JVM does not care what argv[0] was.
But when running a program that uses OpenGL/Direct3D API via Nvidia's driver, it is a bit different:
Here, it _only_ seems to work when the last path-segment of the module name (the first argument to CreateProcess()) _exactly_ matches the last path-segment of the first command-line argument (the second argument to CreateProcess()). This means, the Nvidia driver checks the executable module name (the exe file) and matches this with the last path-segment of argv[0] of the current process.
It does not seem to matter that the path to the exe module name matches (or even would resolve to a valid/existing file), because this in turn works fine:
CreateProcess(TEXT("path\\to\\java.exe"), TEXT("some\\none\\existing\\path\\to\\java.exe -jar the.jar"), ...