• 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 and Notification?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTask and Notification?


  • Subject: Re: NSTask and Notification?
  • From: David Dauer <email@hidden>
  • Date: Fri, 24 Oct 2003 16:56:44 +0200

"Alastair J.Houghton" <email@hidden> schrieb am 24.10.2003 16:24
Uhr :

> On Friday, October 24, 2003, at 02:50 pm, David Dauer wrote:
>
>>> When using pipes, you should always read all of the output from the
>>> process as it arrives, which is what the code David sent appears to
>>> do.
>>> Looking at the code, I would expect to get more than one alert panel
>>> on the screen if the process you started in your NSTask outputs any
>>> substantial amount of data, because you continue to call
>>> -readInBackgroundAndNotify as long as you are receiving data.
>>
>> And *how* can i solve that problem?
>
>> I want use notifications, because the user should be able to work with
>> my program as long as the task gives
>> output. How can i detect when the task don't print anything more so
>> that i can procceed the final output with a function?
>
> When you get a notification with zero bytes of data, there won't be any
> more (it does say this in the documentation, if you follow the link
> from -readInBackgroundAndNotify to -availableData).
>
> You actually already check for this case in your code, although you
> need to move the call to -readInBackgroundAndNotify inside your "if
> ([data length]) {" statement and add an else to the end of your if.
> Something like:
>
> - (void)getOutput:(NSNotification *)aNotification
> {
> ...
> if ([data length]) {
> /* Process data */
> [toolStdout readInBackgroundAndNotify];
> } else {
> /* Finished */
> }
> }
>
> Kind regards,
>
> Alastair.
>

Ah... I did it this way:

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(getOutput:)
name:
NSFileHandleReadToEndOfFileCompletionNotification
object: [[theTask
standardOutput] fileHandleForReading]];



[[[theTask standardOutput] fileHandleForReading]
readToEndOfFileInBackgroundAndNotify];

For me it worked, and i don't need a "[[aNotification object]
readInBackgroundAndNotify]; " in my getOutput method.

Is this a good solution to use
NSFileHandleReadToEndOfFileCompletionNotification and
readToEndOfFileInBackgroundAndNotify?

David
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: NSTask and Notification?
      • From: "Alastair J.Houghton" <email@hidden>
References: 
 >Re: NSTask and Notification? (From: "Alastair J.Houghton" <email@hidden>)

  • Prev by Date: Re: setPropertyList forType / propertyListForType problem on 10.2.8
  • Next by Date: Re: NSTask and Notification?
  • Previous by thread: Re: NSTask and Notification?
  • Next by thread: Re: NSTask and Notification?
  • Index(es):
    • Date
    • Thread