Handle to a Windows CMD with std::command::Command

  Kiến thức lập trình

I am writting a C++ build system that generates some command lines for invoke Microsoft’s MSVC with it’s driver, cl

I have to invoke first a .bat script that set up some ENV VARS for the compiler.
I have a lot of command lines, so I thought that invoking first cmd /c, then run the bat and then store such cmd shell within a variable (like some handle, maybe?) later I could iterate over the commands reusing such shell until I end.

So, I reuse such cmd instance (instead of now, that I am invoking one for every command) and parse the output of the command (it’s status in concrete) with that handle. So the unique change will be having that cmd shell in a handle.

Is that possible with std::command::Command?

Here’s my actual code, invoking the shell for every command:

                    .expect("Zork++ wasn't unable to initialize the VS env vars"),
            .with_context(|| format!("[{compiler}] - Command {:?} failed!", arguments.join(" ")))

Can I have something like a handle in Rust to an std::command::Command that invokes a Windows cmd, and I can Iterate over different cmd lines that a program o’mine generates without having to invoke cmd on every command?