在objective-c中使用命令行运行格式化USB驱动器时出错

在objective-c中使用命令行运行格式化USB驱动器时出错,objective-c,macos,cocoa,command-line,command-line-arguments,Objective C,Macos,Cocoa,Command Line,Command Line Arguments,全部。我是新的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]]

全部。我是新的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/"
但当我在终端中键入这行时,它工作正常。我不知道


谢谢

我明白了。问题在于路径。我应该去掉“

检查此代码。很好用

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