Skip to content

nikstar/Proc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Proc

Convenient process API for Swift.

Swift 5 Platforms Swift Package Manager release GitHub

  • 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")

Examples

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
    }