是否存在允许我的C++代码在Mac上使用hdiutil的系统调用或库。我的代码需要挂载一个可用的.dmg文件,然后操作里面的内容。
发布于 2010-01-06 03:17:43
如果可以使用Objective-C++,则可以使用NSTask运行命令行工具:
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath: @"/usr/bin/hdiutil"];
[task setArguments:
[NSArray arrayWithObjects: @"attach", @"/path/to/dmg/file", nil]];
[task launch];
[task waitUntilExit];
if (0 != [task terminationStatus])
NSLog(@"Mount failed.");
[task release];如果你需要使用“普通”系统,你可以使用C++ ():
if (0 != system("/usr/bin/hdiutil attach /path/to/dmg/file"))
puts("Mount failed.");或者fork()/exec()。
如果成功,您需要仔细检查hdiutil是否返回0。
发布于 2010-01-06 04:10:32
hdiutil使用DiskImages.framework;不幸的是,该框架是私有的(未记录,没有头文件),但是如果您喜欢冒险,可以使用try to use it anyway。
https://stackoverflow.com/questions/2008414
复制相似问题