bare-script 0.1.1

The type-safe scripting authority for Rust. A framework for building robust shell commands and automation with 'Parse, don't validate' philosophy.
Documentation
//! Timeout example - execute command with timeout.
//!
//! Run with: cargo run --example timeout

use bare_script::sync::CommandBuilder;
use std::time::Duration;
use thiserror as _;
use tokio as _;

fn main() {
    // Try to run a command that takes longer than timeout
    #[cfg(windows)]
    let result = {
        CommandBuilder::new("cmd")
            .args(["/C", "ping -n 10 127.0.0.1"])
            .capture_output()
            .execute_with_timeout(Duration::from_millis(100))
    };

    #[cfg(not(windows))]
    let result = {
        CommandBuilder::new("sleep")
            .arg("10")
            .capture_output()
            .execute_with_timeout(Duration::from_millis(100))
    };

    match result {
        Ok(output) => {
            println!("Command completed: {}", output.stdout_str());
        }
        Err(e) => {
            println!("Command timed out or failed: {}", e);
        }
    }
}