https://github.com/nikstar/proc
Convinient process API for Swift
https://github.com/nikstar/proc
cli process swift swift-script
Last synced: 2 months ago
JSON representation
Convinient process API for Swift
- Host: GitHub
- URL: https://github.com/nikstar/proc
- Owner: nikstar
- License: mit
- Created: 2019-07-02T21:52:00.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-08-21T22:36:25.000Z (almost 6 years ago)
- Last Synced: 2025-02-05T11:44:48.869Z (4 months ago)
- Topics: cli, process, swift, swift-script
- Language: Swift
- Homepage:
- Size: 17.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Proc
Convenient process API for Swift.




- [x] Read standard output into a string
- [x] Pipe several commands together
- [x] Change environmentSee `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")
```## Examples
```swift
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.
```swift
let ffmpeg = Proc(name: "ffmpeg", "-version")
// same as Proc("/usr/bin/env", "ffmpeg", "-version") + modified $PATHtry ffmpeg.run()
ffmpeg.waitUntilExit()
```Environment is inhereted from current process and can be modified using `environment`:
```swift
let srv = Proc(name: "myserver")
.environment { env in
env["ACCESS_TOKEN"] = token
}
```