Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/term: Why IsTerminal reports true on redirected stdout? [unrelated] #42003

Closed
gabyx opened this issue Oct 15, 2020 · 7 comments
Closed

x/term: Why IsTerminal reports true on redirected stdout? [unrelated] #42003

gabyx opened this issue Oct 15, 2020 · 7 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@gabyx
Copy link

gabyx commented Oct 15, 2020

What version of Go are you using (go version)?

1.15.2

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/gabyx/Library/Caches/go-build"
GOENV="/Users/gabyx/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/gabyx/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/gabyx/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.15.2/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.15.2/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/gabyx/Desktop/githooks/githooks/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/jf/0dqq5t6x0rxd9kkp8vmc18gc0000gn/T/go-build702825481=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

package main

import (
	"fmt"
	"golang.org/x/term"
	"os"
)

func main() {
    if term.IsTerminal(int(os.Stdout.Fd())) {
        fmt.Println("Is Terminal")
    }
}

and run it with ./run 1> Log.txt.

What did you expect to see?

No output in Log.txt because stdout is redirected?

What did you see instead?

Is Terminal in Log.txt

@gopherbot gopherbot added this to the Unreleased milestone Oct 15, 2020
@ianlancetaylor
Copy link
Contributor

Your program doesn't compile:

foo.go:10:33: cannot use os.Stdout.Fd() (type uintptr) as type int in argument to term.IsTerminal

When I fix that, the program behaves as I expect:

> ./foo
Is Terminal
> ./foo > /tmp/x.txt
> cat /tmp/x.txt
>

Show us a way to reproduce the problem.

@ianlancetaylor ianlancetaylor added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Oct 15, 2020
@gabyx
Copy link
Author

gabyx commented Oct 16, 2020

Updated

@gabyx
Copy link
Author

gabyx commented Oct 16, 2020

Really. I am on Darwin macOs in a Zsh shell. There it happens.

@gabyx
Copy link
Author

gabyx commented Oct 16, 2020

I will provide more infos!

@davecheney
Copy link
Contributor

@gabyx I am using darwin with zsh, I cannot reproduce your findings

(~/src) % go build term.go && ./term | tee log.out
(~/src) % cat log.out
(~/src) % go build term.go && ./term > log.out
(~/src) % cat log.out
(~/src) %

@gabyx
Copy link
Author

gabyx commented Oct 16, 2020 via email

@gabyx
Copy link
Author

gabyx commented Oct 18, 2020

Sorry for your precious time. I mistakenly used the compiled code under a hook invoked by git commit which is where I got confused -> git attaches its stderr to both stdout/stderr of the hook executable... hm...

This works fine.

@gabyx gabyx closed this as completed Oct 18, 2020
@gabyx gabyx changed the title x/term: Why IsTerminal reports true on redirected stdout? x/term: Why IsTerminal reports true on redirected stdout? [unrelated] Oct 18, 2020
@golang golang locked and limited conversation to collaborators Oct 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants