How do you use posix_spawn to replace the deprecated 'system' to launch opendiff in Objective-C?

后端 未结 2 730
-上瘾入骨i
-上瘾入骨i 2021-02-02 02:43

This line of code:

system(\"/Applications/Xcode.app/Contents/Developer/usr/bin/opendiff /Users/LukeSkywalker/Documents/doc1.rtf /Users/LukeSkywalker/Documents/do         


        
2条回答
  •  时光取名叫无心
    2021-02-02 03:01

    Swift 3, Xcode 8.3.1

    func system(_ command: String) {
        var args = command.components(separatedBy: " ")
        let path = args.first
        args.remove(at: 0)
    
        let task = Process()
        task.launchPath = path
        task.arguments = args
        task.launch()
        task.waitUntilExit()
    }
    

提交回复
热议问题