minimal rust library to execute commands
- Rust 100%
|
|
||
|---|---|---|
| src | ||
| .gitignore | ||
| Cargo.lock | ||
| Cargo.toml | ||
| LICENSE | ||
| README.md | ||
ommandz
Zero-dependency Rust library for executing shell commands. in 46kb. (34kb is the license)
Usage
Import the trait and call .exec() on any string:
use ommandz::CommandExt;
let output = "echo hello world".exec().unwrap();
println!("{}", output.stdout_str());
Or use the function directly:
use ommandz::exec;
let output = exec("echo hello world").unwrap();
API
String Extension
The CommandExt trait adds .exec() to str:
"command here".exec() -> Result<Output, Error>
Function
exec(cmd: &str) -> Result<Output, Error>
Output
stdout: Vec<u8>- Raw bytesstderr: Vec<u8>- Raw bytesstatus: ExitStatus- Exit statusstdout_str()- UTF-8 stringstderr_str()- UTF-8 stringsuccess()- True if exit code 0
Error
EmptyCommand- Empty inputSpawnFailed(String)- Failed to runIoError(String)- Read failed
Parsing
Handles shell-like syntax:
'single quotes'- Literal"double quotes"- Literal with escapes\- Escapes next char- Whitespace - Separates args
"sh -c 'echo hello && echo world'".exec()
"echo hello\\ world".exec()
made with ❤️ by landon