Crates.io | apipe |
lib.rs | apipe |
version | 0.2.0 |
source | src |
created_at | 2022-08-21 14:57:16.794183 |
updated_at | 2022-08-29 16:39:09.057792 |
description | An anonymous UNIX pipe type. |
homepage | |
repository | https://github.com/FinalSh4re/apipe-rs |
max_upload_size | |
id | 649816 |
size | 25,836 |
A simple anonymous UNIX pipe type.
The probably easiest way to create a pipe is by parsing a command string:
use apipe::CommandPipe;
let mut pipe = CommandPipe::try_from(r#"echo "This is a test." | grep -Eo \w\w\sa[^.]*"#)?;
let output = pipe.spawn_with_output()?;
assert_eq!(output.stdout(), "is a test\n".as_bytes());
This requires the parser
feature to be enabled.
Create the individual Commands and then contruct a pipe from them:
use apipe::Command;
let mut pipe = Command::parse_str(r#"echo "This is a test.""#)?
| Command::parse_str(r#"grep -Eo \w\w\sa[^.]*"#)?;
// or:
let mut pipe = Command::new("echo").arg("This is a test.")
| Command::new("grep").args(&["-Eo", r"\w\w\sa[^.]*"]);
let output = pipe.spawn_with_output()?;
assert_eq!(output.stdout(), "is a test\n".as_bytes());
Command
s can also be constructed manually if you want:
let mut command = Command::new("ls").arg("-la");
There is also a conventional builder syntax:
use apipe::CommandPipe;
let output = apipe::CommandPipe::new()
.add_command("echo")
.arg("This is a test.")
.add_command("grep")
.args(&["-Eo", r"\w\w\sa[^.]*"])
.spawn_with_output()?;
assert_eq!(output.stdout(), "is a test\n".as_bytes());