Crates.io | command_runner |
lib.rs | command_runner |
version | 0.1.4 |
source | src |
created_at | 2024-06-28 13:23:08.388481 |
updated_at | 2024-06-28 15:21:17.722584 |
description | A library for running system commands |
homepage | |
repository | https://github.com/dbsxdbsx/command_runner |
max_upload_size | |
id | 1286714 |
size | 13,164 |
command_runner
is a cross-platform Rust crate designed for executing terminal commands interactively. It wraps various features in a struct to provide a seamless command execution experience.
Add the following to your Cargo.toml
:
[dependencies]
command_runner = "*"
use anyhow::Result;
use command_runner::CommandRunner;
fn main() -> Result<()> {
let mut runner = CommandRunner::new("echo Hello, World!", 1024)?;
// Check if the command was executed successfully
if runner.get_status() == CommandStatus::Terminated {
println!("Command executed successfully!");
}
// Get the command output
while let Some(output) = runner.get_output() {
println!("Command output: {}", output);
}
// Handle user input
runner.execute("read -p 'Enter your name: ' name && echo \"Hello, $name\"")?;
runner.provide_input("John Doe\n")?;
// Get the final output
while let Some(final_output) = runner.get_output() {
println!("Final output: {}", final_output);
}
Ok(())
}
For more detailed usage instructions and API documentation, please visit docs.rs.
We welcome issues and pull requests. For major changes, please open an issue first to discuss what you would like to change.
This crate is dual-licensed under either:
Choose the license that best fits your needs.