Exception reading pipe from NSTask using debugger
Exception reading pipe from NSTask using debugger
- Subject: Exception reading pipe from NSTask using debugger
- From: James Bucanek <email@hidden>
- Date: Thu, 10 Mar 2005 21:59:49 -0700
Greetings,
I've run into an odd problem. I've got some code that runs the 'ps' command using NSTask. It runs fine if I execute the program. It runs fine if I step through it line-by-line in the debugger. However, if I start the app using the debugger, then let the code run, the statement [stdoutHandle readDataToEndOfFile] throws an exception. This is 100% reproducable.
Here's the code:
NSTask* psTask = [[NSTask alloc] init];
NSPipe* stdoutPipe = [NSPipe pipe];
NSFileHandle* stdoutHandle = [stdoutPipe fileHandleForReading];
NSData* output;
int psStatus = 0;
[psTask setStandardOutput:stdoutPipe];
[psTask setLaunchPath:@"/bin/ps"];
[psTask setArguments:[NSArray arrayWithObjects:@"-axww",@"-o",@"command",nil]];
[psTask launch];
output = [stdoutHandle readDataToEndOfFile];
[psTask waitUntilExit];
psStatus = [psTask terminationStatus];
[psTask release];
The exception:
*** -[NSConcreteFileHandle readDataOfLength:]: Interrupted system call
If I set a breakpoint right before [stdoutHandle readDataToEndOfFile], then step through the code, it works just fine. If I set a breakpoint at [psTask launch] (or don't set any breakpoint at all) then resume execution, readDataToEndOfFile throws the exception.
Searching the archives, I see that this was reported in the summer of 2004. But it doesn't seem to have been confirmed or resolved. Is this worth a bug report?
Finally, I discoverd the following workaround:
...
[psTask launch];
#if NSTASK_DEBUG_HACK
[NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.5]];
#endif
output = [stdoutHandle readDataToEndOfFile];
...
Adding a short delay between launch and readDataToEndOfFile seems to fix the problem.
Other details:
G5 dual 2.5GHz (a sweet machine, by the way)
OS: 10.3.8
XCode: 1.5 (IDE 389.0, Core 387.0, ToolSupport 372.0)
gdb: 5.3-20030128 (Apple version gdb-330.1)
gcc: 3.3 20030304 (Apple Computer, Inc. build 1666)
Can anyone comment on this?
Thanks,
James
--
James Bucanek <mailto:email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden