Setting environment variables on Windows

Hi! I need to set an environment variable from Haskell and i would like to do that cross-platform. There is System.Posix.Env.setEnv, which does exactly, what i want on Linux. There is the module System.Environment, which seems to be cross-platform, but it does not contain functions to manipulate the environment (, just to inspect it). At first glance, I didn't find anything relevant in the sub-modules of System.Win32. Is this just not implemented? How could i implement it myself? Grateful for any comment, Sönke

On Fri, 2009-10-09 at 17:37 +0200, Sönke Hahn wrote:
Hi!
I need to set an environment variable from Haskell and i would like to do that cross-platform. There is System.Posix.Env.setEnv, which does exactly, what i want on Linux. There is the module System.Environment, which seems to be cross-platform, but it does not contain functions to manipulate the environment (, just to inspect it). At first glance, I didn't find anything relevant in the sub-modules of System.Win32.
Note that often it is enough to set environment variables for the programs that you invoke, rather than for your own process. If that's enough then you can do it via the System.Process.createProcess action. Duncan

On Friday 09 October 2009 07:07:21 pm Duncan Coutts wrote:
On Fri, 2009-10-09 at 17:37 +0200, Sönke Hahn wrote:
Hi!
I need to set an environment variable from Haskell and i would like to do that cross-platform. There is System.Posix.Env.setEnv, which does exactly, what i want on Linux. There is the module System.Environment, which seems to be cross-platform, but it does not contain functions to manipulate the environment (, just to inspect it). At first glance, I didn't find anything relevant in the sub-modules of System.Win32.
Note that often it is enough to set environment variables for the programs that you invoke, rather than for your own process. If that's enough then you can do it via the System.Process.createProcess action.
Duncan
Thanks for the suggestion. In my case, that would be a workaround. Maybe still better than writing a .bat-file for the same purpose. Sönke

Hi!
I need to set an environment variable from Haskell and i would like to do
Mmm, that seems like a shortcoming.
Well, you could just wrap the C functions yourself, like this (two
possibilities, no error checking yet, quick hack):
http://hpaste.org/fastcgi/hpaste.fcgi/view?id=10565#a10565
Note that using SetEnvironmentVariable does not seem to be compatible with
getEnv, but calling _putenv does work.
So I guess someone should add this setEnv wrapper to the System.Environment
module? Ticket?
On Fri, Oct 9, 2009 at 5:37 PM, Sönke Hahn
cross-platform. There is System.Posix.Env.setEnv, which does exactly, what i want on Linux. There is the module System.Environment, which seems to be cross-platform, but it does not contain functions to manipulate the environment (, just to inspect it). At first glance, I didn't find anything relevant in the sub-modules of System.Win32.
Is this just not implemented? How could i implement it myself?
Grateful for any comment,
Sönke _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Friday 09 October 2009 07:19:30 pm Peter Verswyvelen wrote:
Mmm, that seems like a shortcoming.
Well, you could just wrap the C functions yourself, like this (two possibilities, no error checking yet, quick hack): http://hpaste.org/fastcgi/hpaste.fcgi/view?id=10565#a10565
Note that using SetEnvironmentVariable does not seem to be compatible with getEnv, but calling _putenv does work.
Both solutions seem to work on my system. Using c_putenv doesn't require linking additional libraries in my case, so i'm going with that. You've been very helpful, thank you very much.
So I guess someone should add this setEnv wrapper to the System.Environment module? Ticket?
Once i figure out, how to implement functions differently for linux and windows, i'll write a ticket with an example module based on your suggestion. Again, many thanks, Sönke
On Fri, Oct 9, 2009 at 5:37 PM, Sönke Hahn
wrote: Hi!
I need to set an environment variable from Haskell and i would like to do
that
cross-platform. There is System.Posix.Env.setEnv, which does exactly, what
i
want on Linux. There is the module System.Environment, which seems to be cross-platform, but it does not contain functions to manipulate the environment (, just to inspect it). At first glance, I didn't find
anything
relevant in the sub-modules of System.Win32.
Is this just not implemented? How could i implement it myself?
Grateful for any comment,
Sönke _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Wednesday 14 October 2009 04:50:56 pm Sönke Hahn wrote:
On Friday 09 October 2009 07:19:30 pm Peter Verswyvelen wrote:
Mmm, that seems like a shortcoming.
Well, you could just wrap the C functions yourself, like this (two possibilities, no error checking yet, quick hack): http://hpaste.org/fastcgi/hpaste.fcgi/view?id=10565#a10565
Note that using SetEnvironmentVariable does not seem to be compatible with getEnv, but calling _putenv does work.
Both solutions seem to work on my system. Using c_putenv doesn't require linking additional libraries in my case, so i'm going with that. You've been very helpful, thank you very much.
So I guess someone should add this setEnv wrapper to the System.Environment module? Ticket?
Once i figure out, how to implement functions differently for linux and windows, i'll write a ticket with an example module based on your suggestion.
Here's the ticket: http://hackage.haskell.org/trac/ghc/ticket/3587
Again, many thanks,
Sönke
On Fri, Oct 9, 2009 at 5:37 PM, Sönke Hahn
wrote: Hi!
I need to set an environment variable from Haskell and i would like to do
that
cross-platform. There is System.Posix.Env.setEnv, which does exactly, what
i
want on Linux. There is the module System.Environment, which seems to be cross-platform, but it does not contain functions to manipulate the environment (, just to inspect it). At first glance, I didn't find
anything
relevant in the sub-modules of System.Win32.
Is this just not implemented? How could i implement it myself?
Grateful for any comment,
Sönke _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (3)
-
Duncan Coutts
-
Peter Verswyvelen
-
Sönke Hahn