NsTask read pipe and big CPU hit

Hi All,

Back with NSTask. I set up NSTask to run rsync and read the output. It works exactly as it should but I found that my app’s CPU usage runs up to 50 or even 60% while the task is on. This is undesirable of course so I have been using my old “do shell script” method to launch the task and reading in output from an external log file, with very little overhead. I would prefer to use NSTask but the CPU issue is daunting. Any thoughts on why this is would be appreciated.

A note: Whether I read input and parse the strings or not doesn’t seem to affect the CPU

Thanks, Rob

in the main script the part that launches the task:

set arraylist to {"-aHAXN", "--progress", pos_path1, pos_path2}
	set thepipe to NSPipe's pipe()
        set theFileHandle to thepipe's fileHandleForReading()
	set theTask to (NSTask's alloc)'s init()
	theTask's setLaunchPath_(rsynPath)
	theTask's setStandardOutput_(thepipe)
	theTask's setArguments_(arraylist)
	theTask's |launch|()
									
	set Nf to NSNotificationCenter's defaultCenter()
	Nf's removeObserver_(me)
	Nf's addObserver_selector_name_object_(me, "readPipe:", "NSFileHandleReadCompletionNotification", theFileHandle)
	Nf's addObserver_selector_name_object_(me, "endPipe:", "NSTaskDidTerminateNotification", theTask)
	theFileHandle's readInBackgroundAndNotify()
readPipe_(aNotification)
     set dataString to aNotification's userInfo's objectForKey_("NSFileHandleNotificationDataItem")
     set newstring to (((current application's class "NSString")'s alloc)'s    initWithData_encoding_(dataString, current application's NSUTF8StringEncoding))
     set parString to newstring as string
     --parse the string for proportionalSize and file_Progress
     --progressBar's setDoubleValue_(proportionalSize)
     --progressField's setStringValue_(file_Progress)
end readPipe_

on endPipe_(aNotification)
  Nf's removeObserver_(me)
  my finishUp_()
end endPipe_