CLIFoundation Documentation Beta

Structure Shell

public struct Shell 

A type that can be used to launch bash commands

Nested Types

Shell.Result

A type that holds information about the output of an executed bash command

Methods

execute(_:​expected​Return​Code:​process:​output​Handle:​error​Handle:​)

@discardableResult public static func execute(
        _ command: String,
        expectedReturnCode: Int32? = nil,
        process: Process = .init(),
        outputHandle: FileHandle? = nil,
        errorHandle: FileHandle? = nil) throws -> Result

Launches a shell command using bash

Parameters

command String

The command to run

expected​Return​Code Int32?

The expected return code

process Process

Which process to use to perform the command (default: A new one)

output​Handle File​Handle?

Any FileHandle that any output (STDOUT) should be redirected to (at the moment this is only supported on macOS)

error​Handle File​Handle?

Any FileHandle that any error output (STDERR) should be redirected to (at the moment this is only supported on macOS)

Throws

In case the command could not be run or the expected return code did not match the resulting one

Returns

The output, error output and return code of the running command

execute(_:​expected​Return​Code:​process:​output​Handle:​error​Handle:​)

@discardableResult public static func execute(
        _ command: ShellCommand,
        expectedReturnCode: Int32? = nil,
        process: Process = .init(),
        outputHandle: FileHandle? = nil,
        errorHandle: FileHandle? = nil) throws -> Result

Launches a shell command using bash

Parameters

command Shell​Command

The ShellCommand instance that will be used to run the command

expected​Return​Code Int32?

The expected return code

process Process

Which process to use to perform the command (default: A new one)

output​Handle File​Handle?

Any FileHandle that any output (STDOUT) should be redirected to (at the moment this is only supported on macOS)

error​Handle File​Handle?

Any FileHandle that any error output (STDERR) should be redirected to (at the moment this is only supported on macOS)

Throws

In case the command could not be run or the expected return code did not match the resulting one

Returns

The output, error output and return code of the running command