I found that on Windows, if a console is generated from stderr, output sent towards the console will go into stdout with extra warning like failed to get console mode for stdout: The handle is invalid.(resovled in 7b7885a).
Verified this with a simple test program in here which simply outputs three messages
// 1. generate console from stderrc, err:=console.ConsoleFromFile(os.Stderr)
iferr!=nil {
fmt.Println("failed to generate console from stderr", err)
os.Exit(1)
}
// 2. output to stderr, stdout and consolefmt.Fprintln(os.Stderr, "via os.Stderr")
fmt.Fprintln(os.Stdout, "via os.Stdout")
fmt.Fprintln(c, "via stderr console")In Powershell, the output is like:
> $a=.\console.exevia os.Stderr
> $afailed to get console mode for stdout: The handle is invalid.via os.Stdoutvia stderr console
The via stderr console log goes wrongly into the variable $a (which should only contain the command's success output stream and stdout output).
As a comparison, below is the behavior of the test program on Zsh(Ubuntu 20.04)
> a=$(./console)via os.Stderrvia stderr console
> echo$avia os.Stdout
We can see tht the via stderr console doesn't goes into the stdout output as expected.
I found that on Windows, if a console is generated from stderr, output sent towards the console will go into stdout
with extra warning like.failed to get console mode for stdout: The handle is invalid.(resovled in 7b7885a)Verified this with a simple test program in here which simply outputs three messages
In Powershell, the output is like:
The
via stderr consolelog goes wrongly into the variable$a(which should only contain the command's success output stream and stdout output).As a comparison, below is the behavior of the test program on Zsh(Ubuntu 20.04)
We can see tht the
via stderr consoledoesn't goes into the stdout output as expected.