         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 {

        task.standardOutput = pipe
        task.standardError = pipe

        let result = launchTask(task, pipe: pipe)
        return result
    }


        self.environment = environment
    }

    public func run() -> Result<String, TerminationStatus> {
        let task = createTask()

        let result = launchTask(task)
        return result
    }

    public func output() -> Result<String, TerminationStatus> {
        let task = createTask()
        task.standardOutput = NSPipe()

        let result = launchTask(task)
        return result
    }

