https://github.com/softprops/pine
process line output
https://github.com/softprops/pine
Last synced: about 1 year ago
JSON representation
process line output
- Host: GitHub
- URL: https://github.com/softprops/pine
- Owner: softprops
- License: mit
- Created: 2015-09-21T00:15:31.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-10-24T20:00:27.000Z (over 10 years ago)
- Last Synced: 2025-03-17T11:59:59.269Z (over 1 year ago)
- Language: Rust
- Homepage:
- Size: 727 KB
- Stars: 13
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pine
[](https://travis-ci.org/softprops/pine) [](https://crates.io/crates/pine)
> line oriented process output
## install
Add the following to your Cargo.toml file
```toml
[dependencies]
pine = "0.1"
```
## apidocs
Find them [here](http://softprops.github.io/pine)
## usage
Rust's interface for working with [processes](https://doc.rust-lang.org/std/process/) is pretty great, but sometimes
you may wish to stream process output as it becomes available rather waiting for the process to exit before you can get
a handle on the total process [output](https://doc.rust-lang.org/std/process/struct.Output.html).
For these usecases, `pine` provides in iterator interface over lines of process output,
represented as enum of `pine::Line::StdOut` or `pine::Line::StdErr`. This is well suited for unix programs with emit
line-oriented output. A prerequite for your program to gain access
to these lines of output, is making sure your child process output is "piped" to your program. Rust's Command interface
makes this simple.
```rust
extern crate pine;
use std::process::{Command, Stdio};
let mut process = Command::new("/bin/sh")
.arg("-c")
.arg("curl https://www.howsmyssl.com/a/check")
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn().ok().unwrap();
```
With the child's output piped to your program, you can then iterate over lines of output as
they are available. using the `pine::lines` function.
```rust
use pine::Line;
let lines = pine::lines(&mut process);
for line in lines.iter() {
match line {
Line::StdOut(line) => println!("out -> {}", line),
Line::StdErr(line) => println!("err -> {}", line)
}
}
```
Note `iter()` returns an iterator, which means any functions defined on iterator are
at your disposal for processing line output.
Doug Tangren (softprops) 2015