1

我使用 NSTask 将 USB 驱动器从 NTFS 格式化为 FAT32。它运作良好,但我想知道它开始格式化时的进度。

这是我的代码:

NSTask *task = [NSTask new];
[task setLaunchPath:@"/usr/bin/env"];
[task setArguments:[NSArray arrayWithObjects:@"diskutil", @"eraseVolume", @"MS-DOS" ,name ,path,nil]];

NSPipe *pipe = [NSPipe pipe];
[task setStandardOutput:pipe];

[task launch];
[task waitUntilExit];

如何添加进度以跟踪格式。(例如完成的百分比......)谢谢!

4

1 回答 1

2

The task you wrap with NSTask needs to be first providing some progress updates. From there, you can watch stderr and stdout. If there are updates to them, you can interpret that and post a notification to the main thread. Use that notification to make any GUI updates.

于 2013-05-13T05:17:03.770 回答