Convenient process API for Swift.
- Read standard output into a string
- Pipe several commands together
- Change environment
See ProcExample
for working example.
This is work in progress. PRs and suggestions are welcome!
Add to your project via Swift package manager:
.package("https://github.com/nikstar/Proc.git", from: "1.0.0")
let ls = Proc("/bin/ls")
let sort = Proc("/usr/bin/sort", "-r")
let wc = Proc("/usr/bin/xargs", "wc", "-c")
let output = try ls
.pipe(to: sort)
.pipe(to: wc)
.runForStdout()
Default initializer takes absolute or relative path as first argument. Convenience initializer init(name:)
takes the name of the tool and uses env
behind the scenes. /usr/local/bin
is added to $PATH
enviroment variable.
let ffmpeg = Proc(name: "ffmpeg", "-version")
// same as Proc("/usr/bin/env", "ffmpeg", "-version") + modified $PATH
try ffmpeg.run()
ffmpeg.waitUntilExit()
Environment is inhereted from current process and can be modified using environment
:
let srv = Proc(name: "myserver")
.environment { env in
env["ACCESS_TOKEN"] = token
}