Skip to content

Commit

Permalink
Merge pull request #13 from NathanFlurry/master
Browse files Browse the repository at this point in the history
Add `backgroundExecuteData` for getting raw `Data` response
  • Loading branch information
NathanFlurry authored Sep 8, 2016
2 parents ef60f09 + 7074061 commit 820642e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Sources/Console/Console/Console.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ extension ConsoleProtocol {
)
}

public func backgroundExecute(program: String, arguments: [String]) throws -> String {
public func backgroundExecuteData(program: String, arguments: [String]) throws -> Data {
let input = Pipe()
let output = Pipe()
let error = Pipe()

do {
try execute(
program: program,
Expand All @@ -111,9 +111,13 @@ extension ConsoleProtocol {
let error = String(data: error.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8) ?? "Unknown"
throw ConsoleError.backgroundExecute(result, error)
}

close(output.fileHandleForWriting.fileDescriptor)
let data = output.fileHandleForReading.readDataToEndOfFile()
return output.fileHandleForReading.readDataToEndOfFile()
}

public func backgroundExecute(program: String, arguments: [String]) throws -> String {
let data = try backgroundExecuteData(program: program, arguments: arguments)
return String(data: data, encoding: .utf8) ?? ""
}
}
Expand Down

0 comments on commit 820642e

Please sign in to comment.