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: could not iterate over named pipes on Windows #32423

Open
Codehardt opened this issue Jun 4, 2019 · 6 comments

Comments

Projects
None yet
5 participants
@Codehardt
Copy link

commented Jun 4, 2019

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

$ go version
go version go1.12.5 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 GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\mars9\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\mars9\go
set GOPROXY=
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 GOMOD=
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\mars9\AppData\Local\Temp\go-build413446826=/tmp/go-build -gno-record-gcc-switches

What did you do?

I wanted to iterate over Windows' named pipes using os package:

	f, err := os.Open(`\\.\pipe`)
	if err != nil {
		log.Fatalf("Could not open pipe list: %s", err)
	}
	defer f.Close()
	stat, err := f.Stat()
	if err != nil {
		log.Fatalf("Could not get file stats: %s", err)
	}
	log.Printf("Is Directory: %t", stat.IsDir()) // output: false
	pipelist, err := f.Readdir(-1)
	if os.IsNotExist(err) {
		log.Print("Pipe list does not exist")
	} else if err != nil {
		log.Printf("Could not read pipe list: %s", err)
	}
	for _, pipe := range pipelist {
		log.Printf("Pipe found: %s", pipe.Name())
	}

What did you expect to see?

The same result as in Python:

for pipeName in os.listdir(r'\\.\pipe'):
    print("Pipe found: %s" % pipeName)
Pipe found: InitShutdown
Pipe found: lsass
Pipe found: ntsvcs
Pipe found: scerpc
...

What did you see instead?

Is Directory: false
Pipe list does not exist
@mdlayher

This comment has been minimized.

Copy link
Member

commented Jun 5, 2019

It isn't clear to me if this is something that the standard library itself should handle, but I recently wrote some Go code to do just this if it helps: https://github.com/WireGuard/wgctrl-go/blob/master/internal/wguser/conn_windows.go#L196.

@mdlayher mdlayher changed the title Could not iterate over named pipes on Windows os: could not iterate over named pipes on Windows Jun 5, 2019

@mdlayher mdlayher added the OS-Windows label Jun 5, 2019

@mdlayher

This comment has been minimized.

Copy link
Member

commented Jun 5, 2019

@alexbrainman

This comment has been minimized.

Copy link
Member

commented Jun 6, 2019

Or sure, maybe we could fix that code.

I don't have time to debug this, but, if someone is interested, maybe they could make code above work. Maybe FindFirstFile and FindNextFile could be used to read that directory.

Alex

@gopherbot

This comment has been minimized.

Copy link

commented Jun 6, 2019

Change https://golang.org/cl/181057 mentions this issue: os: treat the Windows named pipe root as a directory

@Codehardt

This comment has been minimized.

Copy link
Author

commented Jun 7, 2019

Maybe FindFirstFile and FindNextFile could be used to read that directory.

Thanks, this solved my issue.

@mdlayher

This comment has been minimized.

Copy link
Member

commented Jun 7, 2019

I've submitted a patch that makes this work with package os, but it needs a bit more work and it probably won't land until Go 1.14 at this point.

@bradfitz bradfitz added this to the Go1.14 milestone Jun 7, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.