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: Command("dir") not work in powershell on Windows #25070

Closed
dfy167 opened this issue Apr 25, 2018 · 3 comments
Closed

os/exec: Command("dir") not work in powershell on Windows #25070

dfy167 opened this issue Apr 25, 2018 · 3 comments
Labels
FrozenDueToAge help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Milestone

Comments

@dfy167
Copy link

dfy167 commented Apr 25, 2018

Please answer these questions before submitting your issue. Thanks!

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

go version go1.10.1 windows/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

set GOARCH=amd64
set GOBIN=E:\project\go\gopath\bin
set GOCACHE=C:\Users\enen\AppData\Local\go-build
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=E:\project\go\gopath
set GORACE=
set GOROOT=C:\Go
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\enen\AppData\Local\Temp\go-build779536122=/tmp/go-build -gno-record-gcc-switches

What did you do?

        cmd := exec.Command("dir")
	cmd.Stdin = os.Stdin
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	cmd.Run()

in windows cmd console:

go run datax.go
datax.exe  datax.go

in windows powershell console:

go run datax.go

nothing shows

What did you expect to see?

datax.exe datax.go

What did you see instead?

nothing

@ianlancetaylor ianlancetaylor changed the title exec.Command("dir") not work in powershell os/exec: Command("dir") not work in powershell on Windows Apr 25, 2018
@ianlancetaylor ianlancetaylor added OS-Windows NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Apr 25, 2018
@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Apr 25, 2018
@ianlancetaylor
Copy link
Member

I doubt there is anything we can do in Go to fix this, but I'll leave this open in case anybody has an explanation or a solution. You may be more likely to get an answer in a forum such as golang-nuts; see https://golang.org/wiki/Questions.

@dwatley
Copy link

dwatley commented Apr 25, 2018

I can't reproduce this using your code snippet. What's your PowerShell version?

PS C:\Users\Dominic\Projects\Go\src\runtest> go run datax.go
datax.exe  datax.go

PS C:\Users\Dominic\Projects\Go\src\runtest> $PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      17650  1001

@mattn
Copy link
Member

mattn commented Apr 25, 2018

"dir" is internal command of cmd.exe not "dir.exe". You can make sure where dir. If you have dir.exe on your environment, it probably be a command provided from msys2 or mingw commands. Maybe cmd.Run() return error.

FYI, If you want to run dir of cmd.exe, you must call like below.

cmd := exec.Command("cmd", "/c", "dir")
// snip
err := cmd.Run()
if err != nil {
    log.Fatal(err)
}

@dfy167 dfy167 closed this as completed Apr 26, 2018
@golang golang locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Projects
None yet
Development

No branches or pull requests

5 participants