Cbjective-C で小さな rsync プログラムを作成しようとしています。現在、NSTask を介して端末コマンド ラインにアクセスし、コマンド ラインの出力を NSTextField に表示される文字列に読み取ります。ただし、この小さなプログラムを非常に大きなファイル (約 8 GB) で使用すると、RSYNC が完了するまで出力が表示されません。プロセスの実行中に NSTextField を継続的に更新したい。私は次のコードを持っていて、アイデアを探しています!:
-(IBAction)sync:(id)sender
{
NSString *sourcePath = self.source.stringValue;
NSString *destinationPath = self.destination.stringValue;
NSLog(@"The source is %@. The destination is %@.", sourcePath, destinationPath);
NSTask *task;
task = [[NSTask alloc] init];
[task setLaunchPath:@"/usr/bin/rsync"];
NSArray *arguments;
arguments = [NSArray arrayWithObjects: @"-rptWav", @"--progress", sourcePath, destinationPath, nil];
[task setArguments: arguments];
NSPipe *pipe;
pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
// [task setStandardInput:[NSPipe pipe]];
NSFileHandle *file;
file = [pipe fileHandleForReading];
[task launch];
NSData *data;
data = [file readDataToEndOfFile];
while ([task isRunning])
{
NSString *readString;
readString = [[NSString alloc] initWithData: data encoding:NSUTF8StringEncoding];
textView.string = readString;
NSLog(@"grep returned:\n%@", readString);
}
}