https://github.com/nicholasbishop/command-run
Rust library for running a command in a subprocess
https://github.com/nicholasbishop/command-run
command process rust subprocess
Last synced: 5 months ago
JSON representation
Rust library for running a command in a subprocess
- Host: GitHub
- URL: https://github.com/nicholasbishop/command-run
- Owner: nicholasbishop
- License: apache-2.0
- Created: 2020-09-05T08:51:06.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-03-16T16:49:53.000Z (almost 2 years ago)
- Last Synced: 2025-05-09T02:15:30.992Z (8 months ago)
- Topics: command, process, rust, subprocess
- Language: Rust
- Homepage:
- Size: 54.7 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# command-run
[](https://crates.io/crates/command-run)
[](https://docs.rs/command-run)
Rust library for running a command in a subprocess.
This library is a thin wrapper around the [`std::process::Command`]
type with a few additional convenient features:
- Print or log the command before running it
- Optionally return an error if the command is not successful
- Optionally combine stdout and stderr
- Optionally print the command's output if the command fails
- The command can be formatted as a command-line string
- The [`Command`] type can be cloned and its fields are public
## Dependencies and features
- `log` - this is an optional dependency. It can be disabled by
turning off the `logging` feature:
```toml
command-run = { version = "*", default-features = false }
```
- `os_pipe` - this dependency is used to implement `combine_output`.
## Example
```rust
// This will return an error if the command did not exit successfully
// (controlled with the `check` field).
let output = Command::with_args("echo", &["hello", "world"])
.enable_capture()
.run()?;
assert_eq!(output.stdout_string_lossy(), "hello world\n");
```
[`log`]: https://crates.io/crates/log
[`std::process::Command`]: https://doc.rust-lang.org/std/process/struct.Command.html
[`Command`]: https://docs.rs/command-run/latest/command_run/struct.Command.html