Go: proposal: os/exec: method Cmd.String print Env

Created on 18 Aug 2020  路  3Comments  路  Source: golang/go

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

$ go version
go version go1.14.7 linux/amd64

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="/home/janisz/.cache/go-build"
GOENV="/home/janisz/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/janisz/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/snap/go/6274"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/snap/go/6274/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/janisz/go/src/github.com/dcos/dcos-core-cli/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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build069442779=/tmp/go-build -gno-record-gcc-switches"

What did you do?

package main

import (
    "fmt"
    "os/exec"
)

func main() {
    command := exec.Command("echo", "OK")
    command.Env = append(command.Env, "X=1", "Y=2")
    fmt.Println(command.String())
}

https://play.golang.org/p/HTmQGJ12Xhp

What did you expect to see?

X=1 Y=2 /bin/echo OK

What did you see instead?

/bin/echo OK

It this is accepted I'll be happy to provide a patch.
Refs: https://github.com/golang/go/issues/30638

Proposal

Most helpful comment

The Env field is the complete environment to pass to the child process, and is often created by appending to os.Environ(), so that existing environment variables are preserved. In that case the output of the String method might be quite long. My shell has 61 environment variables. I'm not sure that is useful default behavior.

All 3 comments

The Env field is the complete environment to pass to the child process, and is often created by appending to os.Environ(), so that existing environment variables are preserved. In that case the output of the String method might be quite long. My shell has 61 environment variables. I'm not sure that is useful default behavior.

Based on the discussion above, this seems like a likely decline.
(The noise is much larger than the signal.)
It would probably also break existing uses.

No change in consensus, so declined.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bbodenmiller picture bbodenmiller  路  3Comments

longzhizhi picture longzhizhi  路  3Comments

gopherbot picture gopherbot  路  3Comments

natefinch picture natefinch  路  3Comments

rakyll picture rakyll  路  3Comments