The subject of this tutorial is signal handling and working with processes in Rust. We’ll begin by showing how to spawn a new process in Rust – the relevant source file is named spawnNew.rs – without doing anything useful with it, just to show you the simplest form of process spawning. So, the logic of spawnNew.rs is found in the following code excerpt:
All of the work is done by the call to Command ::new() and the use of spawn() . As you might recall from the previous Rust tutorials, the expect() part is executed in case of error. As a reminder, you can replace expect() with unwrap(), but in that case you’re not going to be able to print your own error message.
The screenshot (right) shows part of the code of spawnNew.rs that contains multiple variations of Command::new() that show how to pass arguments to Command::new() and how to set the current directory. You can learn more details about std::process::Command at https://doc.rust-lang.org/std/process/struct.Command.html.
Running generates the output shown in the screenshot (). What’s important in the output is the fact that the error message from the last Command::new() call is printed before the Command::new() call with the .arg(“/doesNotExist”) parameter. This means that currently, we can’t be sure about the order