• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTask is intermittently failing to return results.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTask is intermittently failing to return results.


  • Subject: Re: NSTask is intermittently failing to return results.
  • From: Jason Harris <email@hidden>
  • Date: Fri, 18 Mar 2011 22:04:01 +0100

>
> Hi Jason
>
> I haven't attempted to debug your code but I use NSTask extensively and have experienced some of the problems you describe.
>
> In each case I was not correctly handling the asynchronous availability of data in the pipe ie: there is nothing wrong with the approach but implementation is all.
>
> In my case I found that the implementation detailed in the following sample worked with great reliability on GC apps (search the xcode docs):
>
>
> This sample uses NSFileHandle - waitForDataInBackgroundAndNotify.
> This generates a single notification with all the available data - which may or may not be suitable for your needs.
>
> The sample above calls NSTask - waitUntilExit but that is only a detail I think.
>
> If this was my project I would instigate a branch that implemented the approach detailed in CommandLineToolPlugin.m and see where that got me.
> It should have fewer moving parts at least.
>
> Regards
>
> Jonathan Mitchell
>
> Developer
> Mugginsoft LLP
> http://www.mugginsoft.com


Hi Jonathan,

Thanks for looking at this! It's good to know I am not going crazy and there is some subtle thing I am doing wrong here...

Just to clarify you mean this example here:

http://developer.apple.com/library/mac/#samplecode/CommandLineTool/Listings/CommandLineToolPlugIn_m.html

for the CommandLineToolPlugin.m?

I hadn't  seen this approach at the end of using [task waitUntilExit] after you have set up the observers and notifications. I had seen in eg OpenFileKiller: http://cocoawithlove.com/2009/05/invoking-other-processes-in-cocoa.html and in https://bitbucket.org/snej/myutilities/src/tip/MYTask.m where a run loop is used. Ie something like:

- (void)launchTaskAndRunSynchronous
{
	[task launch];

	BOOL isRunning = YES;
	while (isRunning && (!taskComplete || !outputClosed || !errorClosed))
	{
		isRunning =
			[[NSRunLoop currentRunLoop]
				runMode:NSDefaultRunLoopMode
				beforeDate:[NSDate distantFuture]];
	}
}

(Also just glancing at the code, I noticed a couple of really small things... the date at the top of CommandLineToolPlugin.m lists 2009 yet its using old style NS_DURING, NS_HANDLER, NS_ENDHANDLER which seems a little strange... but its not wrong or anything, just a little well strange. Also it looks like CommandLineToolPlugin.m sets [task setStandardInput:inPipe] whereas I have no input.. Again just small differences. I will have a play and get back to the group.)

Thanks!
   Jas

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSTask is intermittently failing to return results.
      • From: "email@hidden" <email@hidden>
  • Prev by Date: framework and dylib dependency
  • Next by Date: Re: NSMatrix bindings
  • Previous by thread: Re: NSTask is intermittently failing to return results.
  • Next by thread: Re: NSTask is intermittently failing to return results.
  • Index(es):
    • Date
    • Thread