Output/stdout vs println!

When running the examples on this page (https://doc.rust-lang.org/std/process/index.html) locally none of the examples output anything to the terminal. I was expecting something like what println! macro does.

Obviously I was mistaken, so I really would like to know what stdout is really doing vs what println! does. Any help?

This is the return type of the output method (wrapped in a Result) : Output in std::process - Rust

As you can see, stdout is a byte buffer of the captured output of the command.

So I still need the println! macro to get the stdout of output to print to terminal, after conversion to ascii? Is there another option, or is that the best way?

It depends on what you want to do ?

Read the doc (the link you posted), there are a few methods and a few options. You can use spawn with the default options, in the this case the spawned process will inherit your current standard IO handles.

The output method is made to capture the outputs of the child process.

I read the page and ran all of the examples on that page, at least two of which use spawn(), and none of them output anything to the terminal. So it looks like I have to handle sending the stdout/stderr to terminal unless I completely missed something.

That's my bad sorry, spawn doesn't capture the outputs, but makes them available to you (if you wanted to process the output in a streaming fashion). status is probably the method you want.

Yeah, that looks like it does what I was expecting. The docs don't say anything about sending output to terminal, but it does. Thanks!

So it looks like output() gives you a handle to process the data in program. status() just collects the stdout or stderr and sends it to terminal.

That's not exactly it. Simplifying a bit, disregarding the other options of the Command builder :

  • output collects the outputs of the child process
  • spawn starts the child process and lets you handle its outputs as you want
  • status gives your current standard IO streams to the child process, the child process write to them directly