Skip to content

os.exec and file path resolving #73910

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

Closed
mwriter opened this issue May 29, 2025 · 4 comments
Closed

os.exec and file path resolving #73910

mwriter opened this issue May 29, 2025 · 4 comments
Labels
BugReport Issues describing a possible bug in the Go implementation.

Comments

@mwriter
Copy link

mwriter commented May 29, 2025

Go version

1.24.3

Output of go env in your module/workspace:

AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/mwriter/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/mwriter/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build589407262=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/mwriter/go/test/go.mod'
GOMODCACHE='/home/mwriter/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/mwriter/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/mwriter/bin/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='on'
GOTELEMETRYDIR='/home/mwriter/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/mwriter/bin/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.24.3'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

I don't know how such a bug could have gone unnoticed for years, but it still exists.

It's working

import (
	"os"
	"os/exec"
)

func main() {
	p := "some_path"
	os.Setenv("PATH", p);
	cmd := exec.Command("some_binary_name")
	err := cmd.Start() // <nil>
}

But

import (
	"os"
	"os/exec"
)

func main() {
	p := "some_path"
	cmd := exec.Command("some_binary_name")
	os.Setenv("PATH", p);
	err := cmd.Start() // exec: "some_binary_name": executable file not found in $PATH
}
import (
	"fmt"
	"os/exec"
)

func main() {
	p := "some_path"
	cmd := exec.Command("some_binary_name")
	cmd.Env = append([]string{}, fmt.Sprintf("PATH=%v", p))
	err := cmd.Start() // exec: "some_binary_name": executable file not found in $PATH
}

What did you see happen?

I see a big problem in resolving file paths.

What did you expect to see?

Need to change the resolving of file paths not at the time of creation of exec command object, but at the time of its launch. And rewrite it so that the field cmd.Env is also used.

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label May 29, 2025
@seankhliao
Copy link
Member

Closing as working as intended.

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale May 29, 2025
@mwriter
Copy link
Author

mwriter commented May 29, 2025

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

This is an obvious bug, because itself command environment variables are not applied when path resolving.
In other languages, similar constructions work as expected.

@mwriter
Copy link
Author

mwriter commented May 29, 2025

Yes, it's the same bug.
As a result, it turned out to be easier to rewrite golang core code than to wait for your adequacy in solving bugs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation.
Projects
None yet
Development

No branches or pull requests

3 participants