os.SetEnv persistence?

2,433 views
Skip to first unread message

johnalan...@polylabs.ca

unread,
Jul 10, 2013, 2:16:36 AM7/10/13
to golan...@googlegroups.com
Hello All,

Does os.SetEnv persist through computer restarts. If not is there anyway to do it through Go. The only platform under consideration is Linux, but if its possible to do it for all (Windows, Linux, Mac) that would be great.

Dave Cheney

unread,
Jul 10, 2013, 2:21:20 AM7/10/13
to johnalan...@polylabs.ca, golang-nuts
os.SetEnv _only_ changes the environment definition inside your
process. These changes may be visibile to child processes, but only if
you accept the zero value for os/exec.Cmd.Args,
http://golang.org/pkg/os/exec/#Cmd
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Jesse McNelis

unread,
Jul 10, 2013, 2:22:31 AM7/10/13
to johnalan...@polylabs.ca, golang-nuts
On Wed, Jul 10, 2013 at 4:16 PM, <johnalan...@polylabs.ca> wrote:
Hello All,

Does os.SetEnv persist through computer restarts. If not is there anyway to do it through Go. The only platform under consideration is Linux, but if its possible to do it for all (Windows, Linux, Mac) that would be great.

Environment variables are a per process thing. So something needs to store the state to disk and load it in to it's environment and pass that environment on to it's child processes.
This is generally done by the shell, I don't think there is a cross shell way to tell a shell to persist an environment variable to it's configuration.
 

Archos

unread,
Jul 10, 2013, 3:47:10 AM7/10/13
to golan...@googlegroups.com, johnalan...@polylabs.ca
This is something that I need and it is just the next thing I had to develop.
In Unix systems is far easier but I'll have to do a lot of re-search to get it in Windows.
So if you're a little patient...

Archos

unread,
Jul 29, 2013, 8:40:41 AM7/29/13
to golan...@googlegroups.com, johnalan...@polylabs.ca
It is not finished but I want to know if the API is right for you; I've built it thinking also to be used in Windows.
https://github.com/kless/shutil/blob/master/permvar/permvar.go

It depends on shconf [https://github.com/kless/shutil/tree/master/shconf] to get all keys and values without to be commented. When I add, the functions "unset", they will remove the line where it's the key, rather than to comment the line.
Reply all
Reply to author
Forward
0 new messages