Avatar
terminationHandlerの方がいいのかな? リファレンス見る限りではwaitUntilExit()とは別々に動いてるみたい。 @swift-4.2.4 import Foundation let process = Process() process.launchPath = "/bin/false" let semaphore = DispatchSemaphore(value: 0) process.terminationHandler = { _ in semaphore.signal() } let queue = DispatchQueue.global() process.launch() queue.async { process.waitUntilExit() } print("terminationStatus should be 1, actual: \(process.terminationStatus)") semaphore.wait() print("terminationStatus should be 1, actual: \(process.terminationStatus)") (edited)