Skip to content

Commit

Permalink
Merge pull request #66 from muesli/windows-printf
Browse files Browse the repository at this point in the history
fix: don't print to stdout when initializing console fails on Windows
  • Loading branch information
estesp committed Mar 13, 2023
2 parents 917e0fc + 7b7885a commit 1ae8d48
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions console_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ var (
)

func (m *master) initStdios() {
// Note: We discard console mode warnings, because in/out can be redirected.
//
// TODO: Investigate opening CONOUT$/CONIN$ to handle this correctly

m.in = windows.Handle(os.Stdin.Fd())
if err := windows.GetConsoleMode(m.in, &m.inMode); err == nil {
// Validate that windows.ENABLE_VIRTUAL_TERMINAL_INPUT is supported, but do not set it.
Expand All @@ -39,8 +43,6 @@ func (m *master) initStdios() {
// Unconditionally set the console mode back even on failure because SetConsoleMode
// remembers invalid bits on input handles.
windows.SetConsoleMode(m.in, m.inMode)
} else {
fmt.Printf("failed to get console mode for stdin: %v\n", err)
}

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

m.err = windows.Handle(os.Stderr.Fd())
Expand All @@ -61,8 +61,6 @@ func (m *master) initStdios() {
} else {
windows.SetConsoleMode(m.err, m.errMode)
}
} else {
fmt.Printf("failed to get console mode for stderr: %v\n", err)
}
}

Expand Down

0 comments on commit 1ae8d48

Please sign in to comment.