osx - Get Notification of task progress from NSTask -


any body have idea getting notification nstask while nstask executed. unzipping zip file using nstask , need show unzip data progress in nsprogressbar. don't found idea doing such task.so show value in progress bar. need doing task. in advance.

use nsfilehandlereadcompletionnotification, nstaskdidterminatenotification notifications.

task=[[nstask alloc] init];  [task setlaunchpath:path];  nspipe *outputpipe=[[nspipe alloc]init];  nspipe *errorpipe=[[nspipe alloc]init];  nsfilehandle *output,*error;  [task setarguments: arguments];  [task setstandardoutput:outputpipe];  [task setstandarderror:errorpipe];  output=[outputpipe filehandleforreading];  error=[errorpipe  filehandleforreading];  [task launch];    [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(receiveddata:)  name: nsfilehandlereadcompletionnotification object:output];  [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(receivederror:)  name: nsfilehandlereadcompletionnotification object:error];  [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(taskcompletion:)  name: nstaskdidterminatenotification object:task];  //[input writedata:[nsmutabledata initwithstring:@"test"]]; [output readinbackgroundandnotify];  [error readinbackgroundandnotify];   [task waituntilexit];  [outputpipe release];  [errorpipe release]; [task release]; [pool release];   /* called when there data in output pipe */  -(void) receiveddata:(nsnotification*) rec_not  {      nsdata *dataoutput=[[rec_not userinfo] objectforkey:nsfilehandlenotificationdataitem];      [[rec_not object] readinbackgroundandnotify];      [strfromdata release];  }  /* called when there data in error pipe */  -(void) receivederror:(nsnotification*) rec_not  {     nsdata *dataoutput=[[rec_not userinfo] objectforkey:nsfilehandlenotificationdataitem];      if( !dataoutput)          nslog(@">>>>>>>>>>>>>>empty data");      [[rec_not object] readinbackgroundandnotify];   }  /* called when task complete */  -(void) taskcompletion :(nsnotification*) rec_not  {     } 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -