0

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??

Chris Barrett
  • 571
  • 4
  • 23
  • 1
    I think that last argument should be something like `/Users/me/Desktop/testimage.dmg`, no? – Asmus Apr 20 '19 at 20:32
  • Hmm. Just tried that and same message – Chris Barrett Apr 20 '19 at 20:57
  • 1
    You're passing the options wrong. There should be a dash on `size`, `fs`, and `volname`, and the parameter to those need to be separate arguments, not part of the same argument. Also, "Users/me/Desktop" is a relative path (doesn't start with "/"), but looks like it should be absolute. Try: `terminal("create", "-size", "50m" ,"-fs", "HFS+" , "-volname", "test", "/Users/me/Desktop")` – Gordon Davisson Apr 20 '19 at 21:38
  • @GordonDavisson. Thanks. I just got there myself. I omitted the `-` at first thinking that was the issue but as you rightly point out I had to split out the parameter values. Cheers. – Chris Barrett Apr 20 '19 at 21:52

0 Answers0