Skip to content

Commit 25205d6

Browse files
fjlkaralabe
authored andcommitted
[release/1.4.14] cmd/utils: don't check for stderr redirect on windows
The redirect check did not work on Go 1.6 and below because Stat returned an error for stdout and stderr. In Go 1.7 Stat works on stdout but doesn't return anything meaningful, causing cmd/geth test failures because the message is printed to stderr only. Fix it by printing to stdout only. (cherry picked from commit b04219f)
1 parent 03b2f56 commit 25205d6

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

cmd/utils/cmd.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"os"
2424
"os/signal"
2525
"regexp"
26+
"runtime"
2627

2728
"github.com/ethereum/go-ethereum/common"
2829
"github.com/ethereum/go-ethereum/core"
@@ -52,10 +53,16 @@ func openLogFile(Datadir string, filename string) *os.File {
5253
// is redirected to a different file.
5354
func Fatalf(format string, args ...interface{}) {
5455
w := io.MultiWriter(os.Stdout, os.Stderr)
55-
outf, _ := os.Stdout.Stat()
56-
errf, _ := os.Stderr.Stat()
57-
if outf != nil && errf != nil && os.SameFile(outf, errf) {
58-
w = os.Stderr
56+
if runtime.GOOS == "windows" {
57+
// The SameFile check below doesn't work on Windows.
58+
// stdout is unlikely to get redirected though, so just print there.
59+
w = os.Stdout
60+
} else {
61+
outf, _ := os.Stdout.Stat()
62+
errf, _ := os.Stderr.Stat()
63+
if outf != nil && errf != nil && os.SameFile(outf, errf) {
64+
w = os.Stderr
65+
}
5966
}
6067
fmt.Fprintf(w, "Fatal: "+format+"\n", args...)
6168
logger.Flush()

0 commit comments

Comments
 (0)