golang / go

The Go programming language

Home Page:https://go.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

syscall.Exec on Windows

directionless opened this issue · comments

commented

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

$ go version
go1.12

Does this issue reproduce with the latest release?

Yes

What did you do?

I used syscall.Exec on a windows machine.

What did you expect to see?

I expected an exec to happen. Windows does seem to support some set of the exec calls.

What did you see instead?

syscall.Exec: not supported by windows
Due to https://golang.org/src/syscall/exec_windows.go#338

Discussion

I'm not sure what all the context for this is, but is there a reason Exec isn't supported on windows?

As far as I know the _exec function on Windows just starts a new process and exits the current one. You can do that anyhow in Go, using the os/exec package. syscall.Exec on Unix systems starts a new executable in the same process, with the same process ID. I don't think Windows has that facility, so we don't provide syscall.Exec on Windows.

commented

I can't tell.

The docs say exec uses the underlying CreateProcess call, but also that the caller ceases, and all files are open in the new process.

Looking a bit more, it looks like os.Exec wraps os.StartProcess, which wraps syscall.StartProcess which, on windows, is CreateProcess. Between those I probably have all the rope there is to have.

Thank you!