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

proposal: os/exec: method Cmd.String print Env #40860

Closed
janisz opened this issue Aug 18, 2020 · 3 comments
Closed

proposal: os/exec: method Cmd.String print Env #40860

janisz opened this issue Aug 18, 2020 · 3 comments

Comments

@janisz
Copy link

janisz commented Aug 18, 2020

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: #30638

@gopherbot gopherbot added this to the Proposal milestone Aug 18, 2020
@ianlancetaylor ianlancetaylor added this to Incoming in Proposals (old) Aug 19, 2020
@ianlancetaylor
Copy link
Contributor

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.

@rsc rsc moved this from Incoming to Active in Proposals (old) Sep 23, 2020
@rsc
Copy link
Contributor

rsc commented Sep 30, 2020

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.

@rsc rsc moved this from Active to Likely Decline in Proposals (old) Sep 30, 2020
@rsc
Copy link
Contributor

rsc commented Oct 7, 2020

No change in consensus, so declined.

@rsc rsc closed this as completed Oct 7, 2020
@rsc rsc moved this from Likely Decline to Declined in Proposals (old) Oct 7, 2020
@golang golang locked and limited conversation to collaborators Oct 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Development

No branches or pull requests

4 participants