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: StartProcess doesn't allow paths starting with "./" #58743

Closed
xiaq opened this issue Feb 26, 2023 · 1 comment
Closed

os: StartProcess doesn't allow paths starting with "./" #58743

xiaq opened this issue Feb 26, 2023 · 1 comment

Comments

@xiaq
Copy link

xiaq commented Feb 26, 2023

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

$ go version
go version go1.20.1 windows/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
set GO111MODULE=
set GOARCH=amd64
set GOBIN=C:\Users\xiaq\go\bin
set GOCACHE=C:\Users\xiaq\AppData\Local\go-build
set GOENV=C:\Users\xiaq\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\xiaq\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\xiaq\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.20.1
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
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 -fdebug-prefix-map=C:\Users\xiaq\AppData\Local\Temp\go-build1714456318=/tmp/go-build -gno-record-gcc-switches

What did you do?

Save the following program as a.go:

package main

import (
  "log"
  "os"
)

func main() {
  args := os.Args[1:]

  p, err := os.StartProcess(args[0], args[1:], &os.ProcAttr{Files: []*os.File{os.Stdin, os.Stdout, os.Stderr}})
  if err != nil {
    log.Fatalln("StartProcess:", err)
  }
  _, err = p.Wait()
  if err != nil {
    log.Fatalln("Wait:", err)
  }
}

Save the following as foo.bat:

echo foo

Run the following:

go run a.go ./foo.bat

What did you expect to see?

The foo.bat script gets executed successfully.

What did you see instead?

The following output:

'.' is not recognized as an internal or external command,
operable program or batch file.

However, all of the following work:

  • go run a.go .\foo.bat
  • go run a.go c:\users\xiaq\tmp\foo.bat (c:\users\xiaq\tmp is the working directory)
  • go run a.go c:/users/xiaq/tmp/foo.bat

Both / and \ are valid path separators on Windows, and os.StartProcess supports both in an absolute path. Not supporting ./ seems to be a bug.

@seankhliao
Copy link
Member

That's an error from windows, not a limitation Go imposes.
https://stackoverflow.com/questions/20765337/how-to-fix-is-not-an-internal-or-external-command-error

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Feb 27, 2023
@golang golang locked and limited conversation to collaborators Feb 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants