Attempt to hanlde pipes properly under windows

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@21274 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2005-06-04 05:12:40 +00:00
parent 655edeb705
commit 6e3bf6d8a1
2 changed files with 74 additions and 32 deletions

View file

@ -1,10 +1,12 @@
2005-06-04 Richard Frith-Macdonald <rfm@gnu.org> 2005-06-04 Richard Frith-Macdonald <rfm@gnu.org>
GSFileHandle.m: * GSFileHandle.m:
NSFileManager.m: * NSFileManager.m:
Define _FILE_OFFSET_BITS to be 64 so that, on unix-like systems which Define _FILE_OFFSET_BITS to be 64 so that, on unix-like systems which
support large file handling (>2GB) the large file handling routines support large file handling (>2GB) the large file handling routines
are used. are used.
* NSTask.m: Try to deal with pipes properly when launching under
windows.
2005-05-21 Adam Fedor <fedor@gnu.org> 2005-05-21 Adam Fedor <fedor@gnu.org>

View file

@ -1064,17 +1064,19 @@ quotedFromString(NSString *aString)
- (void) launch - (void) launch
{ {
DWORD tid; DWORD tid;
STARTUPINFOW start_info; STARTUPINFOW start_info;
NSString *lpath; NSString *lpath;
NSString *arg; NSString *arg;
NSEnumerator *arg_enum; NSEnumerator *arg_enum;
NSMutableString *args; NSMutableString *args;
wchar_t *w_args; wchar_t *w_args;
int result; int result;
const wchar_t *wexecutable; const wchar_t *wexecutable;
LPVOID envp = 0; LPVOID envp = 0;
NSDictionary *env; NSDictionary *env;
NSMutableArray *toClose;
NSFileHandle *hdl;
if (_hasLaunched) if (_hasLaunched)
{ {
@ -1143,9 +1145,37 @@ quotedFromString(NSString *aString)
memset (&start_info, 0, sizeof(start_info)); memset (&start_info, 0, sizeof(start_info));
start_info.cb = sizeof(start_info); start_info.cb = sizeof(start_info);
start_info.dwFlags |= STARTF_USESTDHANDLES; start_info.dwFlags |= STARTF_USESTDHANDLES;
start_info.hStdInput = [[self standardInput] nativeHandle];
start_info.hStdOutput = [[self standardOutput] nativeHandle]; toClose = [NSMutableArray arrayWithCapacity: 3];
start_info.hStdError = [[self standardError] nativeHandle]; hdl = [self standardInput];
if ([hdl isKindOfClass: [NSPipe class]])
{
hdl = [hdl fileHandleForReading];
[toClose addObject: hdl];
}
start_info.hStdInput = [hdl nativeHandle];
hdl = [self standardOutput];
if ([hdl isKindOfClass: [NSPipe class]])
{
hdl = [hdl fileHandleForWriting];
[toClose addObject: hdl];
}
start_info.hStdOutput = [hdl nativeHandle];
hdl = [self standardError];
if ([hdl isKindOfClass: [NSPipe class]])
{
hdl = [hdl fileHandleForWriting];
/*
* If we have the same pipe twice we don't want to close it twice
*/
if ([toClose indexOfObjectIdenticalTo: hdl] == NSNotFound)
{
[toClose addObject: hdl];
}
}
start_info.hStdError = [hdl nativeHandle];
result = CreateProcessW(wexecutable, result = CreateProcessW(wexecutable,
w_args, w_args,
@ -1175,6 +1205,16 @@ quotedFromString(NSString *aString)
* Create thread to watch for termination of process. * Create thread to watch for termination of process.
*/ */
wThread = CreateThread(NULL, 0, _threadFunction, (LPVOID)self, 0, &tid); wThread = CreateThread(NULL, 0, _threadFunction, (LPVOID)self, 0, &tid);
/*
* Close the ends of any pipes used by the child.
*/
while ([toClose count] > 0)
{
hdl = [toClose objectAtIndex: 0];
[hdl closeFile];
[toClose removeObjectAtIndex: 0];
}
} }
- (void) _collectChild - (void) _collectChild
@ -1250,22 +1290,22 @@ GSCheckTasks()
- (void) launch - (void) launch
{ {
NSMutableArray *toClose; NSMutableArray *toClose;
NSString *lpath; NSString *lpath;
int pid; int pid;
const char *executable; const char *executable;
const char *path; const char *path;
int idesc; int idesc;
int odesc; int odesc;
int edesc; int edesc;
NSDictionary *e = [self environment]; NSDictionary *e = [self environment];
NSArray *k = [e allKeys]; NSArray *k = [e allKeys];
NSArray *a = [self arguments]; NSArray *a = [self arguments];
int ec = [e count]; int ec = [e count];
int ac = [a count]; int ac = [a count];
const char *args[ac+2]; const char *args[ac+2];
const char *envl[ec+1]; const char *envl[ec+1];
id hdl; id hdl;
int i; int i;
if (_hasLaunched) if (_hasLaunched)
{ {