所有。我是新的mac开发人员。我想在objective-c中使用命令行格式化USB驱动器。这是一些代码,当我运行它时会给我错误。
NSTask *task = [NSTask new];
[task setLaunchPath:@"/usr/bin/env"];
[task setArguments:[NSArray arrayWithObjects:@"diskutil", @"eraseVolume",@"MS-DOS",@"PK", @"\"/Volumes/PK/\"", nil]];
....
这是错误:
dyld: DYLD_ environment variables being ignored because main executable (/usr/sbin/diskutil) has __RESTRICT/__restrict section
Unable to find disk for "/Volumes/PK/"
但是当我在终端输入这一行时它工作正常。我不知道。
谢谢!
答案 0 :(得分:1)
答案 1 :(得分:1)
检查此代码。它工作正常。
NSTask *task = [NSTask new];
[task setLaunchPath:@"/usr/bin/env"];
[task setArguments:[NSArray arrayWithObjects:@"diskutil", @"eraseVolume", @"exfat", @"name of pd", @"path of pd",nil]];
NSPipe *pipe = [NSPipe pipe];
[task setStandardOutput:pipe];
[task launch];
[task waitUntilExit];