Output stderr from command.output

Hello,
short question:

let process = Command::new("powershell.exe")
.args (&["-NoProfile","-ExecutionPolicy","ByPass","-File","Internal.ps1"])
.output()
.expect("failed to execute process");

println!("{:?}", String::from_utf8_lossy(&process.stderr));

How can i format &process.stderr that he ouput as .spawn()? I mean .spawn() output an external command error with correctly formated chars and control sequences.

Thx

If you call .stderr(Stdio::inherit()) then the subprocess’ STDERR should be printed to your program’s STDERR. However, I think this is already the default. Is this not what you’re asking?

NOTE: I’m no expert on the topic, but to my knowledge the windows console does not use control sequences. Formatting in Windows is done through system calls, meaning that if you try to log the output of a command (e.g. with Stdio::piped()) it is impossible to preserve formatting. (there may be workarounds but I do not know of them)

@ExpHP Yes thats right when i call .spawn() Command push the output to the windows console, but when i’m use .output() then he puts the output complete in the variable process and i must show how can i deal with an Vec -u8- Variable :smile:.

With .output i can complete control and when i want complete swallow the error.