Merge pull request #6684 from hashicorp/b-nomad-exec-stdout-tty

nomad exec: check stdout for tty as well
This commit is contained in:
Mahmood Ali 2019-11-19 15:55:21 -05:00 committed by GitHub
commit 97974c4b13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 5 deletions

View File

@ -105,8 +105,8 @@ func (l *AllocExecCommand) Run(args []string) int {
flags.BoolVar(&stdinOpt, "i", true, "")
stdinTty := isStdinTty()
flags.BoolVar(&ttyOpt, "t", stdinTty, "")
inferredTty := isTty()
flags.BoolVar(&ttyOpt, "t", inferredTty, "")
if err := flags.Parse(args); err != nil {
return 1
@ -292,9 +292,11 @@ func (l *AllocExecCommand) execImpl(client *api.Client, alloc *api.Allocation, t
alloc, task, tty, command, stdin, stdout, stderr, sizeCh, nil)
}
func isStdinTty() bool {
_, isTerminal := term.GetFdInfo(os.Stdin)
return isTerminal
// isTty returns true if both stdin and stdout are a TTY
func isTty() bool {
_, isStdinTerminal := term.GetFdInfo(os.Stdin)
_, isStdoutTerminal := term.GetFdInfo(os.Stdout)
return isStdinTerminal && isStdoutTerminal
}
// setRawTerminal sets the stream terminal in raw mode, so process captures