Command
public protocol Command : AnyObject
                Represents a description of a command that can be executed any number of times, but usually just once.
- 
                  
                  
The minimum requirement of a Command is that it can launch itself asynchronously
Declaration
Swift
func coreAsync(fdMap: FDMap) -> CommandResultParameters
fdMapA map from child FDs to parent FDs
Return Value
a result capable of monitoring the asynchronous command
 
- 
                  
run()Extension methodRun the command asynchronously, and return nothing if successful
Throws
if command failsDeclaration
Swift
@available(macOS 10.15, *) public func run() async throws - 
                  
runBool()Extension methodRun the command asynchronously, and return true if the command exited zero
Declaration
Swift
@available(macOS 10.15, *) public func runBool() async -> Bool - 
                  
runFile()Extension methodRun the command synchronously, directing the output to a temporary file
Throws
if command failsDeclaration
Swift
@available(macOS 10.15, *) public func runFile() async throws -> URLReturn Value
URL of temporary file with output of command
 - 
                  
runData()Extension methodRun the command synchronously, and collect stdout. does not trim newlines (unlike $(…))
Throws
if command failsDeclaration
Swift
@available(macOS 10.15, *) public func runData() async throws -> DataReturn Value
output as Data
 - 
                  
runString(encoding:)Extension methodRun the command asynchronously, and collect stdout into a string. Trims trailing newlines (like $(…))
Throws
if command failsThrows
InvalidStringif the output isn’t validDeclaration
Swift
@available(macOS 10.15, *) public func runString(encoding: String.Encoding = .utf8) async throws -> StringParameters
encodingthe encoding of the output data
Return Value
output as unicode string
 - 
                  
runLines(encoding:)Extension methodRun the command asynchronously, and collect output line-by-line as a list of strings
Throws
if command failsDeclaration
Swift
@available(macOS 10.15, *) public func runLines(encoding: String.Encoding = .utf8) async throws -> [String] - 
                  
runJSON(options:)Extension methodRun the command asynchronously, and collect output as a parsed JSON object
Throws
if command failsThrows
if the output isn’t JSONDeclaration
Swift
@available(macOS 10.15, *) public func runJSON(options: JSONSerialization.ReadingOptions = .allowFragments) async throws -> Any - 
                  
runJSON(_:decoder:)Extension methodRun the command asynchronously, and collect output as a parsed JSON object
Throws
if command failsThrows
if parsing failsDeclaration
Swift
@available(macOS 10.15, *) public func runJSON<D>(_ type: D.Type, decoder: JSONDecoder? = nil) async throws -> D where D : Decodable - 
                  
async(fdMap:)Extension methodRun the command asynchronously, inheriting or overwriting the standard file descriptors
Declaration
Swift
public func async(fdMap: FDMap = [:]) -> CommandResultParameters
fdMapA map from child FDs to parent FDs, will be composed with standard map
Return Value
a result capable of monitoring the asynchronous command
 - 
                  
async(stdin:stdout:stderr:)Extension methodRun the command asynchronously, inheriting or overwriting the standard file descriptors
Declaration
Swift
public func async( stdin: FileDescriptor = .stdin, stdout: FileDescriptor = .stdout, stderr: FileDescriptor = .stderr ) -> CommandResult - 
                  
asyncStream()Extension methodRun the command asynchronously, and return a stream open on process’s stdout
Declaration
Swift
public func asyncStream() -> FileHandle - 
                  
run()Extension methodRun the command synchronously, and return nothing if successful
Throws
if command failsDeclaration
Swift
public func run() throws - 
                  
runBool()Extension methodRun the command synchronously, and return true if the command exited zero
Declaration
Swift
public func runBool() -> Bool - 
                  
runFile()Extension methodRun the command synchronously, directing the output to a temporary file
Throws
if command failsDeclaration
Swift
public func runFile() throws -> URLReturn Value
URL of temporary file with output of command
 - 
                  
runData()Extension methodRun the command synchronously, and collect stdout. does not trim newlines (unlike $(…))
Throws
if command failsDeclaration
Swift
public func runData() throws -> DataReturn Value
output as Data
 - 
                  
runString(encoding:)Extension methodRun the command synchronously, and collect stdout into a string. Trims trailing newlines (like $(…))
Throws
if command failsThrows
InvalidStringif the output isn’t validDeclaration
Swift
public func runString(encoding: String.Encoding = .utf8) throws -> StringParameters
encodingthe encoding of the output data
Return Value
output as unicode string
 - 
                  
runLines(encoding:)Extension methodRun the command synchronously, and collect output line-by-line as a list of strings
Throws
if command failsDeclaration
Swift
public func runLines(encoding: String.Encoding = .utf8) throws -> [String] - 
                  
runJSON(options:)Extension methodRun the command synchronously, and collect output as a parsed JSON object
Throws
if command failsThrows
if the output isn’t JSONDeclaration
Swift
public func runJSON(options: JSONSerialization.ReadingOptions = .allowFragments) throws -> Any - 
                  
runJSON(_:decoder:)Extension methodRun the command synchronously, and collect output as a parsed JSON object
Throws
if command failsThrows
if parsing failsDeclaration
Swift
public func runJSON<D>(_ type: D.Type, decoder: JSONDecoder? = nil) throws -> D where D : Decodable 
- 
                  
output(creatingFile:fd:)Extension methodBind output to a file. Similar to “>” in bash, but will not overwrite the file
Declaration
Swift
public func output(creatingFile path: String, fd: FileDescriptor = .stdout) -> CommandParameters
pathPath to write output to
fdFile descriptor to bind. Defaults to stdout
 - 
                  
output(overwritingFile:fd:)Extension methodBind output to a file, creating if needed. Similar to “>” in bash
Declaration
Swift
public func output(overwritingFile path: String, fd: FileDescriptor = .stdout) -> CommandParameters
pathPath to write output to
fdFile descriptor to bind. Defaults to stdout
 - 
                  
append(toFile:fd:createFile:)Extension methodBind output to end of a file. Similar to “>>” in bash
Throws
FileDoesntExist if createFile is false, and the file doesn’t existDeclaration
Swift
public func append(toFile path: String, fd: FileDescriptor = .stdout, createFile: Bool = true) -> CommandParameters
pathPath to write output to
fdFile descriptor to bind. Defaults to stdout
createFilefail if the file doesn’t exist
 - 
                  
duplicateFd(source:destination:)Extension methodDuplicate a file handle. In bash, this is expressed like “2>&1”. See also dup2(2)
Declaration
Swift
public func duplicateFd(source srcFd: FileDescriptor, destination dstFd: FileDescriptor) -> CommandParameters
srcFdFile descriptor to duplicate
dstFdDescriptor of new, duplicated handle
 - 
                  
combineErrorExtension methodRedirect standard error to standard output. “2>&1” in bash
Declaration
Swift
public var combineError: Command { get } 
- 
                  
input(_:encoding:fd:)Extension methodBind stdin to contents of string
Throws
ThrowsDeclaration
Swift
public func input( _ string: String, encoding: String.Encoding = .utf8, fd: FileDescriptor = .stdin ) throws -> CommandParameters
encodinghow encoding the outgoing data
fdFile descriptor to bind. Defaults to stdin
 - 
                  
input(_:fd:)Extension methodBind stdin to contents of data
Declaration
Swift
public func input(_ data: Data, fd: FileDescriptor = .stdin) -> CommandParameters
fdFile descriptor to bind. Defaults to stdin
 - 
                  
input(withJSONObject:fd:options:)Extension methodBind stdin to the the JSON representation of a JSON-like value
Throws
if encoding failsDeclaration
Swift
public func input( withJSONObject json: Any, fd: FileDescriptor = .stdin, options: JSONSerialization.WritingOptions = .init() ) throws -> CommandParameters
jsonAnything
JSONSerializationcan deal withfdFile descriptor to bind. Defaults to stdin
 - 
                  
inputJSON(from:fd:encoder:)Extension methodBind stdin to the the JSON representation of a JSON-encodable value
Throws
if encoding failsDeclaration
Swift
public func inputJSON<E: Encodable>( from object: E, fd: FileDescriptor = .stdin, encoder: JSONEncoder = .init() ) throws -> CommandParameters
objectThe object to be encoded and sent
fdFile descriptor to bind. Defaults to stdin
encoderJSONEncoder to use
 - 
                  
input(fromFile:fd:)Extension methodBind stdin to a file, similar to
< filein bashDeclaration
Swift
public func input(fromFile path: String, fd: FileDescriptor = .stdin) -> CommandParameters
fdFile descriptor to bind. Defaults to stdin
 
View on GitHub
        Command Protocol Reference