NSTask and NSPipe has buffering issues?

2012-07-31 Thread Mr. Gecko
I am having weird results with NSTask. It sometimes retrieves the output, and other times receives nothing. I have example code for this issue at https://dl.dropbox.com/u/610721/NSTask%20Issue.zip The result I have is below: 0 Starting 0 Received /bin/ls 0 Done 1 Starting 1 Received 1 Done 2 S

Re: NSTask and NSPipe has buffering issues?

2012-07-31 Thread Wim Lewis
On 31 Jul 2012, at 3:33 PM, Mr. Gecko wrote: > I am having weird results with NSTask. It sometimes retrieves the output, and > other times receives nothing. I haven't looked at the code you posted, but is it possible that you're reading from the NSPipe in such a way that you're mixing up the "e

Re: NSTask and NSPipe has buffering issues?

2012-07-31 Thread Mr. Gecko
What do you recommend after the task finishes? I have tried [[outPipe fileHandleForReading] readDataToEndOfFile] after the task finishes and it doesn't seem to improve. Can you maybe give me an example of how to do this right? On Jul 31, 2012, at 6:01 PM, Wim Lewis wrote: > I haven't looked a

Re: NSTask and NSPipe has buffering issues?

2012-07-31 Thread Kyle Sluder
On Tue, Jul 31, 2012, at 03:33 PM, Mr. Gecko wrote: > I am having weird results with NSTask. It sometimes retrieves the output, > and other times receives nothing. > > I have example code for this issue at > https://dl.dropbox.com/u/610721/NSTask%20Issue.zip NSTask requires a running runloop. You

Re: NSTask and NSPipe has buffering issues?

2012-07-31 Thread Mr. Gecko
I have multiple run loops. On the main thread I have [[NSRunLoop currentRunLoop] run]; On the sub threads for NSTask and NSPipe, I have CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, YES); If you are saying that you have to use NSRunLoop in order for it to work, get it working in my example and

Re: NSTask and NSPipe has buffering issues?

2012-07-31 Thread Kyle Sluder
On Jul 31, 2012, at 6:53 PM, "Mr. Gecko" wrote: > > I can confirm if you do not stop the run loop, it will get everything… > However… I cannot do this as I do not know how much data I am receiving from > the task. 1) Yes, you need to run the run loop forever (NSDistantFuture). 2) You don't n

Re: NSTask and NSPipe has buffering issues?

2012-07-31 Thread Mr. Gecko
I need threads because the main thread is a network loop waiting for a connection and when it gets a connection, it spawns a thread like in my example. I need to be able to respond to the client with all the data from the task and I need to close out the connection and release the spawned threa

Re: NSTask and NSPipe has buffering issues?

2012-07-31 Thread Jens Alfke
On Jul 31, 2012, at 7:43 PM, Mr. Gecko wrote: > I need threads because the main thread is a network loop waiting for a > connection and when it gets a connection, it spawns a thread like in my > example. I need to be able to respond to the client with all the data from > the task and I need t

Re: NSTask and NSPipe has buffering issues?

2012-07-31 Thread Ken Thomases
NSPipe itself doesn't require that a run loop be run, but the "InBackgroundAndNotify" methods of the associated NSFileHandle objects do. You receive a zero-length NSData when (and only when) a read encounters EOF. There is an inherent race between the receipt of the task termination notificatio

Re: NSTask and NSPipe has buffering issues?

2012-08-01 Thread Mr. Gecko
Thank you! That makes lots of sense and I was able to fix my code. I knew that I sometimes got zero length data, but never knew why. Now that I know it's the end of file… I can make lots of use of this knowledge. Thanks for the help. On Jul 31, 2012, at 11:20 PM, Ken Thomases wrote: > NSPipe