What strategy use to run command async in rust?

Hi there

I'm new to rust and I'm trying to create a CLI using Ratatui. This CLI will have a list of commands to run like: ['comand-1', 'command-2', 'command-3']. I have successfully use std::process::Command to run the command but the problem is that the user can't interact with the cli while the command is running.

I think I can solve this with async but I don't know what module/crate/library/strat to for this use-case. Really appreciate your help.

Thankss!

If you intend to go the async route, I'd recommend Tokio as the async runtime you use, using the elements of tokio::process to run your commands.

That said, there's a simpler option; if you use Command::spawn to start the command, it runs asynchronously to your main process, and you can call Child::try_wait to check to see if the command you've started has completed yet; you also have access to stdin, stdout and stderr for the child process if that's relevant to you.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.