A posix-compliant library to run external applications and capture the standard out and standard error.
If you are developing cross platform command line apps, you need an easy way to run external applications. Process
provides just that.
You can use Process
with Guaka to create aweseome command line applications.
To execute a simple command you would do:
let result = Process.exec("ls -a -l")
print(result.stdout)
result
type is RunResults
, it contains:
exitStatus
: The command exit statusstdout
: The standard output for the command executedstderr
: The standard error for the command executed
To customize the run function, you can pass in a customization block:
let result = Process.exec("ls -all") { settings in
settings.dryRun = true
settings.echo = [.Stdout, .Stderr, .Command]
settings.interactive = false
}
settings
is an instance of RunSettings, which contains the following variables:
settings.dryRun
: defaults to false. If false, the command is actually run. If true, the command is logged to the stdout paramter of resultsettings.echo
: Customize the message printed to stdout,echo
can contain any of the following:EchoSettings.Stdout
: The stdout returned from running the command will be printed to the terminalEchoSettings.Stderr
: The stderr returned from running the command will be printed to the terminalEchoSettings.Command
: The command executed will be printed to the terminal
You can install Process using Swift package manager (SPM) and carthage
Add Process as dependency in your Package.swift
import PackageDescription
let package = Package(name: "YourPackage",
dependencies: [
.Package(url: "https://github.com/oarrabi/Process.git", majorVersion: 0),
]
)
github 'oarrabi/Process'
Tests can be found here.
Run them with
swift test
Just send a PR! We don't bite ;)