2

全部。我是新的mac开发人员。我想在objective-c中使用命令行格式化USB驱动器。这里有一些代码,当我运行它时它会给我错误。使用命令行运行格式化USB驱动器时发生错误,目标-c

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/" 

但是,当我在终端上键入该行正常工作。我不知道。

谢谢!

回答

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]; 
相关问题