Skip to content

Commit

Permalink
Ensure we log to STDOUT on Windows without a TTY -- otherwise scripts…
Browse files Browse the repository at this point in the history
… fail when they see something on stderr
  • Loading branch information
bdwyertech committed Mar 2, 2023
1 parent 99c9086 commit 3a43877
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// Better CFN Signal
//
// Copyright © 2022 Brian Dwyer - Intelligent Digital Services
// Copyright © 2023 Brian Dwyer - Intelligent Digital Services
//

package main
Expand All @@ -18,6 +18,7 @@ import (
"net"
"net/http"
"os"
"runtime"
"strings"
"time"

Expand All @@ -29,6 +30,7 @@ import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cloudformation"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/mattn/go-isatty"
)

var healthcheckUrl string
Expand All @@ -44,6 +46,12 @@ func init() {
log.SetLevel(log.DebugLevel)
log.SetReportCaller(true)
}

// Workaround for https://github.com/PowerShell/PowerShell/issues/14273
// PSNotApplyErrorActionToStderr
if runtime.GOOS == "windows" && !(isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd())) {
log.SetOutput(os.Stdout)
}
}

func main() {
Expand Down

0 comments on commit 3a43877

Please sign in to comment.