C++ interface for hdiutil on Mac
Does a system call or library exist that would allow my C++ code to use hdiutil on Mac OS X. My code needs to 开发者_高级运维mount an available .dmg file and then manipulate what's inside.
If you can use Objective-C++, you can use NSTask to run command line tools:
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];
If you need to use "plain" C++, you can use system():
if (0 != system("/usr/bin/hdiutil attach /path/to/dmg/file"))
puts("Mount failed.");
or fork()/exec().
You'll need to double-check whether hdiutil
actually returns 0 for success or not.
hdiutil
uses DiskImages.framework; unfortunately, the framework is private (undocumented, no headers), but if you're feeling adventurous, you can try to use it anyway.
hdiutil
has a -plist
argument that causes it to format its output as a standard OS X plist. See this for info on processing the output from hdiutil; because you'll likely have to examine the output a bit to find what you need, it may be easy to do this initially with something like python
. Then see here for some suggestions on parsing plists in C++.
精彩评论