JohnSundell / ShellOut

Easily run shell commands from a Swift script or command line tool
MIT License
870 stars 83 forks source link

allow to use pipes #37

Open emilwojtaszek opened 6 years ago

emilwojtaszek commented 6 years ago

With this simple change we can pipe commands, like:

echo "Hello world" | cat

example use:

let pipe = Pipe()

// echo "Hello world"
let _ = try shellOut(to: "echo", arguments: ["Hello world"], outputHandle: pipe.fileHandleForWriting)

// simulate `echo "Hello world" | cat`
let output = try shellOut(to: "cat", inputHandle: pipe.fileHandleForReading)