Skip to content

Commit 1ae8d48

Browse files
authored
Merge pull request #66 from muesli/windows-printf
fix: don't print to stdout when initializing console fails on Windows
2 parents 917e0fc + 7b7885a commit 1ae8d48

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

console_windows.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ var (
3030
)
3131

3232
func (m *master) initStdios() {
33+
// Note: We discard console mode warnings, because in/out can be redirected.
34+
//
35+
// TODO: Investigate opening CONOUT$/CONIN$ to handle this correctly
36+
3337
m.in = windows.Handle(os.Stdin.Fd())
3438
if err := windows.GetConsoleMode(m.in, &m.inMode); err == nil {
3539
// Validate that windows.ENABLE_VIRTUAL_TERMINAL_INPUT is supported, but do not set it.
@@ -39,8 +43,6 @@ func (m *master) initStdios() {
3943
// Unconditionally set the console mode back even on failure because SetConsoleMode
4044
// remembers invalid bits on input handles.
4145
windows.SetConsoleMode(m.in, m.inMode)
42-
} else {
43-
fmt.Printf("failed to get console mode for stdin: %v\n", err)
4446
}
4547

4648
m.out = windows.Handle(os.Stdout.Fd())
@@ -50,8 +52,6 @@ func (m *master) initStdios() {
5052
} else {
5153
windows.SetConsoleMode(m.out, m.outMode)
5254
}
53-
} else {
54-
fmt.Printf("failed to get console mode for stdout: %v\n", err)
5555
}
5656

5757
m.err = windows.Handle(os.Stderr.Fd())
@@ -61,8 +61,6 @@ func (m *master) initStdios() {
6161
} else {
6262
windows.SetConsoleMode(m.err, m.errMode)
6363
}
64-
} else {
65-
fmt.Printf("failed to get console mode for stderr: %v\n", err)
6664
}
6765
}
6866

0 commit comments

Comments
 (0)