 
         task.launch()
         task.waitUntilExit()
-        return Int(task.terminationStatus)
+        let status = Int(task.terminationStatus)
+        if exitOnFailure && status != 0 {
+            exitMsg("Error: \(command) failed with exit code \(status)")
+        }
+        return status
     }
 }
    /// Launches the given command with the working directory set to path (or the parent directory if path is a file)
    ///
    /// Returns a tuple with status, stdout and stderr
    public func launchCommandForOutput(command: String, arguments: [String] = []) -> (Int, String, String) {
        var outString: String = ""
        var errString: String = ""
        let status = launchCommand(command, arguments: arguments, configure:  { task in

    /// Launches the given command with the working directory set to path (or the parent directory if path is a file), forwarding stderr and stdout to the current process
    ///
    /// Returns the status.
    public func launchCommand(command: String, arguments: [String] = [], exitOnFailure: Bool = false) -> Int {
        return launchCommand(command, arguments: arguments, configure: { task in
            task.standardOutput = NSFileHandle.fileHandleWithStandardOutput()
            task.standardError = NSFileHandle.fileHandleWithStandardError()
