Re: Exception reading pipe from NSTask using debugger
Re: Exception reading pipe from NSTask using debugger
- Subject: Re: Exception reading pipe from NSTask using debugger
- From: email@hidden
- Date: Thu, 10 Mar 2005 21:48:05 -0800
Well, your code runs fine in the scenarios you give on my PB17 1.33GHz,
10.3.8 (no haxies...) so it might be an issue that only shows up on
dual CPU machines. If you have the CHUD tools installed you'll have a
'Hardware' System Preference that can turn off one of your G5's cpus to
see if that makes a difference. The CHUD tools are not installed by
default, but they are located on the Xcode developer tools CD.
If you know you will always have less data than the socket buffers
(~32K if memory serves) you could try calling -waitUntilExit before
-readDataToEndOfFile.
(Also, in my code I wrap -launch in an exception handler since the
documentation says it can raise an exception if something prevents the
process from running...)
Cheers,
ChrisF
On Mar 10, 2005, at 8:59 PM, James Bucanek wrote:
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
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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