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

os/exec: execution of internal command at Windows gives error #67358

Open
tredoe opened this issue May 14, 2024 · 4 comments
Open

os/exec: execution of internal command at Windows gives error #67358

tredoe opened this issue May 14, 2024 · 4 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@tredoe
Copy link

tredoe commented May 14, 2024

Go version

go version go1.22.2 windows/amd64

Output of go env in your module/workspace:

set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\neo\AppData\Local\go-build
set GOENV=C:\Users\neo\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\lib\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\lib\go;C:\Users\neo\Projects\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.22.2
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\neo\Projects\go\osutil\go.mod
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\neo\AppData\Local\Temp\go-build930553209=/tmp/go-build -gno-record-gcc-switches

What did you do?

package executil

import (
	"os/exec"
	"testing"
)

func TestEcho(t *testing.T) {
	cmd := exec.Command("echo", "ok")
	if err := cmd.Run(); err != nil {
		t.Fatal(err)
	}
}

What did you see happen?

exec: "echo": executable file not found in %PATH%

What did you expect to see?

'echo' is an internal command at Windows so it can not found in %PATH%.

@bjorndm
Copy link

bjorndm commented May 14, 2024

Commands of the shell itself cannot be executed directly, this is so on all platforms. You will need to place the command in a batch script and execute that indirectly using CMD.exe.

@dmitshur
Copy link
Contributor

CC @golang/windows.

@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 14, 2024
@dmitshur dmitshur added this to the Backlog milestone May 14, 2024
@dmitshur
Copy link
Contributor

This is probably working as intended. If there was a command named echo in %PATH%, would it be executed? If so, it might not be a responsibility of os/exec to track which builtins on various platforms.

@alexbrainman
Copy link
Member

This is probably working as intended.

I agree.

If there was a command named echo in %PATH%, would it be executed?

If a file named echo.exe would be found in the %PATH%, it would be executed. If a file named echo would be found in the %PATH%, it would not be executed.

Alex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants