Using Process to Create a DMG with hdiutil

908 Views Asked by At

I'm having a play with Process() and trying to get it to create a DMG on my Desktop.

The code I'm trying is:

func terminal(_ args:String...) -> integer_t{
print(args)
let task = Process()
let dataPipe = Pipe()
let errPipe = Pipe()


task.launchPath = "/usr/bin/hdiutil"
task.arguments = args
task.standardOutput = dataPipe
task.standardError = errPipe

task.launch()

task.waitUntilExit()

let data = dataPipe.fileHandleForReading.readDataToEndOfFile()
let output = String(data: data, encoding: String.Encoding.utf8)

let dataErr = errPipe.fileHandleForReading.readDataToEndOfFile()
let errOp = String(data: dataErr, encoding: String.Encoding.utf8)
print (errOp)


return task.terminationStatus}

terminal("create", "size 50m" ,"fs HFS+" , "volname test", "Users/me/Desktop")

But currently it throws an error

hdiutil: create: Only one image can be created at a time.\nUsage:\thdiutil create <sizespec> [options] <imagepath>\n\thdiutil create -help\n

I guess I have something wrong with the way the arguments are parsed but not sure what.

Thanks for any help!

UPDATE:

I think maybe its seeing the arguments as seperate calls? The top of the returned error reads

["create", "size 50m", "fs HFS+", "/Users/me/Desktop/test.dmg"] hdiutil: create: Only one image can be created at a time.

I put the - back into the arguments but now it says hdiutil: create: unknown option "-size 50M". Definitely something to do with how the arguments are formatted but seems correct I think??

0

There are 0 best solutions below