How do i return a value from a thread func

⚓ Rust    📅 2025-09-07    👤 surdeus    👁️ 9      

surdeus

Warning

This post was published 66 days ago. The information described in this article may have changed.

i want to return Result<String,Box<dyn Error>> from a function that i pass to a thread spawn

pub fn launch_app(command: &String) -> Result<String, Box<dyn Error>> {
    let output = Command::new("sh").arg("-c").arg(command).output()?.stdout;

    let cmd_output = String::from_utf8(output)?;

    Ok(cmd_output)
}

What will be the best way to do so ?

6 posts - 3 participants

Read full topic

🏷️ Rust_feed