gpt4 book ai didi

objective-c - objective-c : How to know the progress of formatting USB drive in using NSTask

转载 作者:行者123 更新时间:2023-12-03 17:03:47 25 4
gpt4 key购买 nike

我使用 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];

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

最佳答案

使用 NSTask 包装的任务需要首先提供一些进度更新。从那里,您可以观看 stderr 和 stdout。如果有更新,您可以对其进行解释并向主线程发布通知。使用该通知进行任何 GUI 更新。

关于objective-c - objective-c : How to know the progress of formatting USB drive in using NSTask,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16514397/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com