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: LookPath is hard-coded to os.Getenv("PATH") #20081

Closed
mvdan opened this issue Apr 22, 2017 · 3 comments
Closed

os/exec: LookPath is hard-coded to os.Getenv("PATH") #20081

mvdan opened this issue Apr 22, 2017 · 3 comments

Comments

@mvdan
Copy link
Member

mvdan commented Apr 22, 2017

I'm writing a Shell interpreter in Go and I've come across a limitation in the os/exec package. In particular, when it comes to the interpreter state keeping track of the environment variable PATH.

exec.LookPath is hard-coded to using os.Getenv("PATH"), and so exec.Command is too. This is unfortunate as it means that the interpreter must modify the process's PATH to be able to use its own when running a command. But as you can imagine, that will not work well if there are multiple interpreters running concurrently.

Would it be possible for os/exec to have a LookPath version that got PATH from a string argument or similar? Then the existing LookPath could be rewritten in terms of it. In other words, a LookPath version that didn't depend on the process's environment.

I realise it's a bit of a bizarre request, but I can't figure out another way to do it other than maintaining a fork of LookPath myself.

@mvdan
Copy link
Member Author

mvdan commented Apr 22, 2017

Perhaps it wouldn't be that easy given that this is only in lp_unix.go - Plan9 and Windows use different env vars in different ways.

@bradfitz
Copy link
Contributor

I realise it's a bit of a bizarre request, but I can't figure out another way to do it other than maintaining a fork of LookPath myself.

You're writing a shell interpreter. It's okay to fork something like LookPath if you need something non-standard.

There's no reason to pollute the standard library with something that two people need. That means everybody else in the ecosystem needs to read over your new LookPath docs just to realize it wasn't what they were looking for.

Feel free to put yours up at github.com/mvdan/lookpath

@mvdan
Copy link
Member Author

mvdan commented Apr 22, 2017

Fair enough, thanks!

@golang golang locked and limited conversation to collaborators Apr 22, 2018
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