A shell interface built as a thin abstraction layer over Foundation's Process
.
// -- Simple use case example:
let shell = ExecuteCommand()
let result = shell.execute(command: "cat",
arguments: ["/tmp/log.0.txt", "/tmp/log.1.txt"],
waitUntilExit: true)
// -- Customization example:
var context = TaskContext()
context.environment = ["HOME": "/Users/me"]
context.workingDirectory = "/tmp/"
let bash = ExecuteCommand(pathToShell: "/bin/bash")
_ = bash.execute(command: "curl", arguments: ["http://example.org"], context: context, waitUntilExit:false)
// -- Error reporting examples:
print(result.standardError)
guard let terminationStatus = result.terminationStatus else {
throw TaskFailure.stillRunning(domain: #function, code: #line)
}
guard terminationStatus == 0 else {
throw TaskFailure.nonzeroTerminationStatus(
domain: #function,
code: #line,
terminationStatus: terminationStatus,
uncaughtSignal: result.terminatedDueUncaughtSignal
)
}
guard !result.standardOutput.isEmpty else {
throw TaskFailure.emptyOutput(domain: #function, code: #line)
}
ShellInterface is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "ShellInterface"
ShellInterface is available under the MIT license. See the LICENSE file for more info.