From 09f63cea0bcd2ac5696a3583a6d6081be0adce95 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Mon, 3 Jun 2019 14:13:36 -0700 Subject: [PATCH] processinfo --- main.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index ff4ced0a7..f687390cb 100644 --- a/main.go +++ b/main.go @@ -25,6 +25,7 @@ import ( "github.com/mitchellh/cli" "github.com/mitchellh/panicwrap" "github.com/mitchellh/prefixedio" + "github.com/shirou/gopsutil/process" ) func main() { @@ -192,7 +193,12 @@ func wrappedMain() int { } ui = basicUi if !inPlugin { - if TTY, err := openTTY(); err != nil { + currentPID := os.Getpid() + myProc, _ := process.NewProcess(int32(currentPID)) + bg, _ := myProc.Background() + if bg { + fmt.Fprint(os.Stderr, "Running in background, not using a TTY\n") + } else if TTY, err := openTTY(); err != nil { fmt.Fprintf(os.Stderr, "No tty available: %s\n", err) } else { basicUi.TTY = TTY