mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* win32/win32.c (mypopen): fixed that mypclose() didn't really close
pipe. * win32/win32.c (CreateChild): set STARTF_USESTDHANDLES flag only when some handles are passed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1859 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5444b117f2
commit
43271e97ab
2 changed files with 84 additions and 28 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
Mon Nov 26 16:54:59 2001 Usaku Nakamura <usa@ruby-lang.org>
|
||||||
|
|
||||||
|
* win32/win32.c (mypopen): fixed that mypclose() didn't really close
|
||||||
|
pipe.
|
||||||
|
|
||||||
|
* win32/win32.c (CreateChild): set STARTF_USESTDHANDLES flag only
|
||||||
|
when some handles are passed.
|
||||||
|
|
||||||
Sun Nov 25 21:02:18 2001 Usaku Nakamura <usa@ruby-lang.org>
|
Sun Nov 25 21:02:18 2001 Usaku Nakamura <usa@ruby-lang.org>
|
||||||
|
|
||||||
* parse.y (str_extend): change types of second and third arguments
|
* parse.y (str_extend): change types of second and third arguments
|
||||||
|
|
104
win32/win32.c
104
win32/win32.c
|
@ -444,7 +444,8 @@ mypopen (char *cmd, char *mode)
|
||||||
int pipemode;
|
int pipemode;
|
||||||
struct ChildRecord* child;
|
struct ChildRecord* child;
|
||||||
BOOL fRet;
|
BOOL fRet;
|
||||||
HANDLE hInFile, hOutFile;
|
HANDLE hInFile, hOutFile, hSavedStdIo, hDupFile;
|
||||||
|
HANDLE hCurProc;
|
||||||
SECURITY_ATTRIBUTES sa;
|
SECURITY_ATTRIBUTES sa;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
|
@ -468,30 +469,75 @@ mypopen (char *cmd, char *mode)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* save parent's STDIO and redirect for child */
|
||||||
|
hCurProc = GetCurrentProcess();
|
||||||
if (reading) {
|
if (reading) {
|
||||||
child = CreateChild(cmd, &sa, NULL, hOutFile, NULL);
|
hSavedStdIo = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
|
if (!SetStdHandle(STD_OUTPUT_HANDLE, hOutFile) ||
|
||||||
|
!DuplicateHandle(hCurProc, hInFile, hCurProc, &hDupFile, 0, FALSE,
|
||||||
|
DUPLICATE_SAME_ACCESS)) {
|
||||||
|
errno = GetLastError();
|
||||||
|
CloseHandle(hInFile);
|
||||||
|
CloseHandle(hOutFile);
|
||||||
|
CloseHandle(hCurProc);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
CloseHandle(hInFile);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
child = CreateChild(cmd, &sa, hInFile, NULL, NULL);
|
hSavedStdIo = GetStdHandle(STD_INPUT_HANDLE);
|
||||||
}
|
if (!SetStdHandle(STD_INPUT_HANDLE, hInFile) ||
|
||||||
|
!DuplicateHandle(hCurProc, hOutFile, hCurProc, &hDupFile, 0, FALSE,
|
||||||
if (!child) {
|
DUPLICATE_SAME_ACCESS)) {
|
||||||
CloseHandle(hInFile);
|
errno = GetLastError();
|
||||||
|
CloseHandle(hInFile);
|
||||||
|
CloseHandle(hOutFile);
|
||||||
|
CloseHandle(hCurProc);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
CloseHandle(hOutFile);
|
CloseHandle(hOutFile);
|
||||||
|
}
|
||||||
|
CloseHandle(hCurProc);
|
||||||
|
|
||||||
|
/* create child process */
|
||||||
|
child = CreateChild(cmd, &sa, NULL, NULL, NULL);
|
||||||
|
if (!child) {
|
||||||
|
CloseHandle(reading ? hOutFile : hInFile);
|
||||||
|
CloseHandle(hDupFile);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* restore STDIO */
|
||||||
if (reading) {
|
if (reading) {
|
||||||
fd = _open_osfhandle((long)hInFile, (_O_RDONLY | pipemode));
|
if (!SetStdHandle(STD_OUTPUT_HANDLE, hSavedStdIo)) {
|
||||||
|
errno = GetLastError();
|
||||||
|
CloseChildHandle(child);
|
||||||
|
CloseHandle(hDupFile);
|
||||||
|
CloseHandle(hOutFile);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (!SetStdHandle(STD_INPUT_HANDLE, hSavedStdIo)) {
|
||||||
|
errno = GetLastError();
|
||||||
|
CloseChildHandle(child);
|
||||||
|
CloseHandle(hInFile);
|
||||||
|
CloseHandle(hDupFile);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reading) {
|
||||||
|
fd = _open_osfhandle((long)hDupFile, (_O_RDONLY | pipemode));
|
||||||
CloseHandle(hOutFile);
|
CloseHandle(hOutFile);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fd = _open_osfhandle((long)hOutFile, (_O_WRONLY | pipemode));
|
fd = _open_osfhandle((long)hDupFile, (_O_WRONLY | pipemode));
|
||||||
CloseHandle(hInFile);
|
CloseHandle(hInFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
CloseHandle(reading ? hInFile : hOutFile);
|
CloseHandle(hDupFile);
|
||||||
CloseChildHandle(child);
|
CloseChildHandle(child);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -571,24 +617,26 @@ CreateChild(char *cmd, SECURITY_ATTRIBUTES *psa, HANDLE hInput, HANDLE hOutput,
|
||||||
memset(&aStartupInfo, 0, sizeof (STARTUPINFO));
|
memset(&aStartupInfo, 0, sizeof (STARTUPINFO));
|
||||||
memset(&aProcessInformation, 0, sizeof (PROCESS_INFORMATION));
|
memset(&aProcessInformation, 0, sizeof (PROCESS_INFORMATION));
|
||||||
aStartupInfo.cb = sizeof (STARTUPINFO);
|
aStartupInfo.cb = sizeof (STARTUPINFO);
|
||||||
aStartupInfo.dwFlags = STARTF_USESTDHANDLES;
|
if (hInput || hOutput || hError) {
|
||||||
if (hInput) {
|
aStartupInfo.dwFlags = STARTF_USESTDHANDLES;
|
||||||
aStartupInfo.hStdInput = hInput;
|
if (hInput) {
|
||||||
}
|
aStartupInfo.hStdInput = hInput;
|
||||||
else {
|
}
|
||||||
aStartupInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
|
else {
|
||||||
}
|
aStartupInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
|
||||||
if (hOutput) {
|
}
|
||||||
aStartupInfo.hStdOutput = hOutput;
|
if (hOutput) {
|
||||||
}
|
aStartupInfo.hStdOutput = hOutput;
|
||||||
else {
|
}
|
||||||
aStartupInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
|
else {
|
||||||
}
|
aStartupInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
if (hError) {
|
}
|
||||||
aStartupInfo.hStdError = hError;
|
if (hError) {
|
||||||
}
|
aStartupInfo.hStdError = hError;
|
||||||
else {
|
}
|
||||||
aStartupInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE);
|
else {
|
||||||
|
aStartupInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dwCreationFlags = (NORMAL_PRIORITY_CLASS);
|
dwCreationFlags = (NORMAL_PRIORITY_CLASS);
|
||||||
|
|
Loading…
Add table
Reference in a new issue