os.Setenv bug?

531 views
Skip to first unread message

salviati

unread,
Mar 1, 2011, 5:56:13 PM3/1/11
to golang-nuts
I needed pass a few environment parameters to SDL (http://
www.libsdl.org/docs/html/sdlenvvars.html), but os.Setenv doesn't seem
to be doing the job. I wrapped stdlib's setenv as a hack and it works,
but I'm wondering whether if this is a bug or not.

Dave Cheney

unread,
Mar 1, 2011, 6:08:42 PM3/1/11
to salviati, golang-nuts
I dont' think os.SetEnv pushes the env variables back into the process
environment space, it just updates the Go hash map that is populated
on first access.

http://code.google.com/p/go/source/browse/src/pkg/os/env_unix.go#56

Dave

Brad Fitzpatrick

unread,
Mar 1, 2011, 6:32:14 PM3/1/11
to Dave Cheney, salviati, golang-nuts
And that basically works if you only are using exec.Run to start child processes and passing in os.Environ() as the envv parameter.

But yeah, it won't work if you're making calls into C which is then checking getenv.

It's probably worth fixing, with documentation if nothing else.  Want to file an issue?

salviati

unread,
Mar 1, 2011, 6:40:34 PM3/1/11
to golang-nuts
> It's probably worth fixing, with documentation if nothing else.
Indeed, the documentation is misleading:
"Setenv sets the value of the environment variable named by the key."

> Want to file an issue?
Done: http://code.google.com/p/go/issues/detail?id=1569

brainman

unread,
Mar 1, 2011, 7:04:29 PM3/1/11
to golan...@googlegroups.com, Dave Cheney, salviati
On Wednesday, March 2, 2011 10:32:14 AM UTC+11, Brad Fitzpatrick wrote:

It's probably worth fixing, with documentation if nothing else...


FYI, windows code does update os environment:

http://code.google.com/p/go/source/browse/src/pkg/os/env_windows.go#48

Alex
Reply all
Reply to author
Forward
0 new messages