         self.environment = environment
     }
 
-    public func run() -> Result<(), Int32> {
+    public func run() -> Result<String, TerminationStatus> {
         let task = createTask()
-        task.launch()
-        task.waitUntilExit()
 
-        if task.terminationStatus == EXIT_SUCCESS {
-            return .success()
-        } else {
-            return .failure(task.terminationStatus)
-        }
+        let result = launchTask(task)
+        return result
     }
 
     public func output() -> Result<String, TerminationStatus> {
         let task = createTask()
+        task.standardOutput = NSPipe()
 
-        let pipe = NSPipe()
-        task.standardOutput = pipe
-
-        let result = launchTask(task, pipe: pipe)
+        let result = launchTask(task)
         return result
     }
 

        return task
    }

    private func launchTask(task: NSTask, pipe: NSPipe) -> Result<String, TerminationStatus> {
        if task.standardOutput.fileHandleForReading != nil {
            task.standardOutput.fileHandleForReading.readabilityHandler = { fileHandle in
                if let string = NSString(data: fileHandle.availableData, encoding: NSUTF8StringEncoding) {

        task.launch()
        task.waitUntilExit()

        task.terminationHandler = { task in
            if task.standardOutput.fileHandleForReading != nil {
                task.standardOutput.fileHandleForReading.readabilityHandler = nil
            }
            if task.standardError.fileHandleForReading != nil {
                task.standardError.fileHandleForReading.readabilityHandler = nil
            }
        }

        if task.terminationStatus == EXIT_SUCCESS {
            return .success(outputString)
        } else {
