Question

I use NSTask to execute format USB drive from NTFS to FAT32. It works well, but I would like to know the progress when it starts to format.

Here is my code:

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];

How to add progress to keep track of the formatting.(like the percentage done...) Thanks !!

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top