src/windows/native/java/lang/ProcessImpl_md.c
Print this page
@@ -143,14 +143,14 @@
HANDLE outWrite = INVALID_HANDLE_VALUE;
HANDLE errRead = INVALID_HANDLE_VALUE;
HANDLE errWrite = INVALID_HANDLE_VALUE;
SECURITY_ATTRIBUTES sa;
PROCESS_INFORMATION pi;
- STARTUPINFO si;
- LPTSTR pcmd = NULL;
- LPCTSTR pdir = NULL;
- LPVOID penvBlock = NULL;
+ STARTUPINFOW si;
+ const jchar* pcmd = NULL;
+ const jchar* pdir = NULL;
+ const jchar* penvBlock = NULL;
jlong *handles = NULL;
jlong ret = 0;
OSVERSIONINFO ver;
jboolean onNT = JNI_FALSE;
DWORD processFlag;
@@ -159,26 +159,21 @@
GetVersionEx(&ver);
if (ver.dwPlatformId == VER_PLATFORM_WIN32_NT)
onNT = JNI_TRUE;
assert(cmd != NULL);
- pcmd = (LPTSTR) JNU_GetStringPlatformChars(env, cmd, NULL);
+ pcmd = (*env)->GetStringChars(env, cmd, NULL);
if (pcmd == NULL) goto Catch;
if (dir != 0) {
- pdir = (LPCTSTR) JNU_GetStringPlatformChars(env, dir, NULL);
+ pdir = (*env)->GetStringChars(env, dir, NULL);
if (pdir == NULL) goto Catch;
- pdir = (LPCTSTR) JVM_NativePath((char *)pdir);
}
-
if (envBlock != NULL) {
- penvBlock = onNT
- ? (LPVOID) ((*env)->GetStringChars(env, envBlock, NULL))
- : (LPVOID) JNU_GetStringPlatformChars(env, envBlock, NULL);
+ penvBlock = ((*env)->GetStringChars(env, envBlock, NULL));
if (penvBlock == NULL) goto Catch;
}
-
assert(stdHandles != NULL);
handles = (*env)->GetLongArrayElements(env, stdHandles, NULL);
if (handles == NULL) goto Catch;
memset(&si, 0, sizeof(si));
@@ -237,29 +232,18 @@
if (onNT)
processFlag = CREATE_NO_WINDOW | CREATE_UNICODE_ENVIRONMENT;
else
processFlag = selectProcessFlag(env, cmd);
- /* Java and Windows are both pure Unicode systems at heart.
- * Windows has both a legacy byte-based API and a 16-bit Unicode
- * "W" API. The Right Thing here is to call CreateProcessW, since
- * that will allow all process-related information like command
- * line arguments to be passed properly to the child. We don't do
- * that currently, since we would first have to have "W" versions
- * of JVM_NativePath and perhaps other functions. In the
- * meantime, we can call CreateProcess with the magic flag
- * CREATE_UNICODE_ENVIRONMENT, which passes only the environment
- * in "W" mode. We will fix this later. */
-
- ret = CreateProcess(0, /* executable name */
- pcmd, /* command line */
+ ret = CreateProcessW(0, /* executable name */
+ (LPWSTR)pcmd, /* command line */
0, /* process security attribute */
0, /* thread security attribute */
TRUE, /* inherits system handles */
processFlag, /* selected based on exe type */
- penvBlock, /* environment block */
- pdir, /* change to the new current directory */
+ (LPVOID)penvBlock,/* environment block */
+ (LPCWSTR)pdir, /* change to the new current directory */
&si, /* (in) startup information */
&pi); /* (out) process information */
if (!ret) {
win32Error(env, "CreateProcess");
@@ -274,22 +258,17 @@
closeSafely(inRead);
closeSafely(outWrite);
closeSafely(errWrite);
if (pcmd != NULL)
- JNU_ReleaseStringPlatformChars(env, cmd, (char *) pcmd);
+ (*env)->ReleaseStringChars(env, cmd, pcmd);
if (pdir != NULL)
- JNU_ReleaseStringPlatformChars(env, dir, (char *) pdir);
- if (penvBlock != NULL) {
- if (onNT)
- (*env)->ReleaseStringChars(env, envBlock, (jchar *) penvBlock);
- else
- JNU_ReleaseStringPlatformChars(env, dir, (char *) penvBlock);
- }
+ (*env)->ReleaseStringChars(env, dir, pdir);
+ if (penvBlock != NULL)
+ (*env)->ReleaseStringChars(env, envBlock, penvBlock);
if (handles != NULL)
(*env)->ReleaseLongArrayElements(env, stdHandles, handles, 0);
-
return ret;
Catch:
/* Clean up the parent's side of the pipes in case of failure only */
closeSafely(inWrite);