How to catch error when setting launchpath in NSTask

后端 未结 3 1306
野的像风
野的像风 2021-01-18 02:58

I am trying to run a commandline tool using swift 2 on a mac (10.10):

let task = NSTask()
task.launchPath = \"/path/to/wrong/binary\"
task.launch()

// NSPip         


        
3条回答
  •  无人共我
    2021-01-18 03:37

    In Mac OS X High Sierra, launch() is deprecated. You would use run() instead:

    let process = Process()
    // ...
    
    do {
        process.run()
    } catch let error as NSError {
        print(error.localizedDescription)
        // ...
    }
    

    Also have a look at the Apple Dev Docs

提交回复
热议问题