U-Bend
This is a small crate that lets you build pipe chains between spawned processes using a syntax similar to the Unix shell.
extern crate ubend;
use IntoPipeSetup;
let output = ubend!.expect.
output.
expect.
stdout;
let output = String from_utf8.
expect.
trim.
.
unwrap;
println!;
Note that arguments to commands need always to be quoted. If you don't quote
them they are interpreted as Rust identifiers which allows you to pass
dynamic strings. Also FOO="bar" cat <"baz"
is the same as
FOO = "bar" cat < "baz"
, since whitespace is ignored in Rust.
use ubend::IntoPipeSetup
is needed when passing a file name or
std::fs::File
as redirection source/target.
Note: Currently only Linux ist tested. Other Unix operating systems might work, too. Windows support is not implemented.
More Examples
extern crate ubend;
use IntoPipeSetup;
use *;
use File;
use ;
// Ignore stderr
ubend!;
// Redirect stderr to stdout
ubend!;
// Write stderr to stderr of this process
ubend!;
// Read from a file opened in Rust
let file = open.
expect;
ubend!;
// Write stderr to a temp file
let mut chain = ubend!.
expect;
chain.wait_last.
expect;
let mut temp = chain.stderr.unwrap;
// Since the file descriptor was shared with the spawned process the
// position needs to be reset manually:
temp.seek.
expect;