How it works...

A child process is created via the Command struct, which is responsible for the spawning process. Here, we declared a variable output where we called the new method. This is the place where we entered the main command to run. Next, we had arg, which contained the options of a particular system command. The output response was responsible for getting the output and the other commands used for error handling.

The struct child basically has three fields: pub stdin: Option<ChildStdin>, pub stdout: Option<ChildStdout>, and pub stderr: Option<ChildStderr>. These fields handle represent functionalities such as standard input, output, and error, respectively.

In the if...else statement, we basically checked whether the Command had executed properly using the status module's success method, which returns True in case of success and False otherwise. In both the cases, we captured the error and output, which we printed by &output.stdout and &output.stderr.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.148.104.242