https://github.com/sephiroth74/simple-cmd
Rust command exeuctor
https://github.com/sephiroth74/simple-cmd
Last synced: 10 months ago
JSON representation
Rust command exeuctor
- Host: GitHub
- URL: https://github.com/sephiroth74/simple-cmd
- Owner: sephiroth74
- Created: 2023-12-20T11:14:33.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-02-13T08:22:13.000Z (11 months ago)
- Last Synced: 2025-02-28T08:45:31.560Z (11 months ago)
- Language: Rust
- Size: 102 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# simple-cmd
[](https://crates.io/crates/simple-cmd/)
[](https://github.com/sephiroth74/simple-cmd/actions/workflows/rust.yml)
Rust command exeuctor
Example:
```rust
use simple_cmd::Cmd;
use simple_cmd::prelude::*;
use tracing::trace;
use std::time::Duration;
pub fn main() {
let cmd = Cmd::builder("sleep")
.arg("1")
.timeout(Some(Duration::from_millis(100)))
.with_debug(true)
.build();
let output = cmd.output().expect("failed to wait for command");
trace!("output: {:#?}", output);
assert!(!output.status.success());
assert!(!output.interrupt());
assert!(output.kill());
}
```
Piping:
```rust
use simple_cmd::Cmd;
use simple_cmd::prelude::*;
fn test_pipe() {
let builder = Cmd::builder("echo").args(&["hello pretty world"]).with_debug(true);
let command1 = builder.build();
let mut command2 = Command::new("sed");
command2.args(&["s/pretty/_/"]);
command2.stdout(Stdio::piped());
let result = command1.pipe(command2).unwrap();
let output = result.stdout.as_str().unwrap().trim();
assert!(result.success());
assert_eq!("hello _ world", output);
}
```