< prev index next >
src/os/windows/vm/os_windows.cpp
Print this page
*** 5248,5263 ****
// Run the specified command in a separate process. Return its exit value,
// or -1 on failure (e.g. can't create a new process).
int os::fork_and_exec(char* cmd) {
STARTUPINFO si;
PROCESS_INFORMATION pi;
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
memset(&pi, 0, sizeof(pi));
BOOL rslt = CreateProcess(NULL, // executable name - use command line
! cmd, // command line
NULL, // process security attribute
NULL, // thread security attribute
TRUE, // inherits system handles
0, // no creation flags
NULL, // use parent's environment block
--- 5248,5281 ----
// Run the specified command in a separate process. Return its exit value,
// or -1 on failure (e.g. can't create a new process).
int os::fork_and_exec(char* cmd) {
STARTUPINFO si;
PROCESS_INFORMATION pi;
+ DWORD exit_code;
+ char * cmd_string;
+ char * cmd_prefix = "cmd /C ";
+ size_t len = strlen(cmd) + strlen(cmd_prefix) + 1;
+ cmd_string = NEW_C_HEAP_ARRAY_RETURN_NULL(char, len, mtInternal);
+ if (cmd_string == NULL) {
+ return -1;
+ }
+ cmd_string[0] = '\0';
+ strcat(cmd_string, cmd_prefix);
+ strcat(cmd_string, cmd);
+
+ // now replace all '\n' with '&'
+ char * substring = cmd_string;
+ while ((substring = strchr (substring, '\n')) != NULL) {
+ substring[0] = '&';
+ substring++;
+ }
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
memset(&pi, 0, sizeof(pi));
BOOL rslt = CreateProcess(NULL, // executable name - use command line
! cmd_string, // command line
NULL, // process security attribute
NULL, // thread security attribute
TRUE, // inherits system handles
0, // no creation flags
NULL, // use parent's environment block
*** 5267,5287 ****
if (rslt) {
// Wait until child process exits.
WaitForSingleObject(pi.hProcess, INFINITE);
- DWORD exit_code;
GetExitCodeProcess(pi.hProcess, &exit_code);
// Close process and thread handles.
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
-
- return (int)exit_code;
} else {
! return -1;
}
}
bool os::find(address addr, outputStream* st) {
int offset = -1;
bool result = false;
--- 5285,5305 ----
if (rslt) {
// Wait until child process exits.
WaitForSingleObject(pi.hProcess, INFINITE);
GetExitCodeProcess(pi.hProcess, &exit_code);
// Close process and thread handles.
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
} else {
! exit_code = -1;
}
+
+ FREE_C_HEAP_ARRAY(char, cmd_string);
+ return (int)exit_code;
}
bool os::find(address addr, outputStream* st) {
int offset = -1;
bool result = false;
< prev index next >