matze77 has asked for the wisdom of the Perl Monks concerning the following question:

Could someone help me with the correct syntax? To add a simple "string" to the path variable? This is the example code from the moduls web-page:

Win32::Env::Path
use Win32::Env::Path; my $path = Win32::Env::Path->new( name => 'PATH', ); $path->add('C:\\strawberry');
Or Should i use a different Update: module, script, method whatever?
Why: I have to deal with a local app (which executable is on a mapped network ressource) which needs to be in the path of all users. I want to automate this, cause it occurs on every new machine which joins the Windows 2003 domain ... I hope it is easier now to understand what i want? I could of course use something like autoit autoit to do it but i think it should be possible otherwise?
/Update
Solved using the script:
CleanPath
Special Thanks to tye
Thanks MH
  • Comment on Trying to use [cpan://Win32::Env::Path] to change Windows Path Variable?
  • Download Code

Replies are listed 'Best First'.
Re: Trying to use [cpan://Win32::Env::Path] to change Windows Path Variable? (CleanPath)
by tye (Sage) on Nov 17, 2009 at 18:03 UTC

    You might prefer to use CleanPath (a script, not a module).

    - tye        

      Yes. Exactly what i want i think i might modify it to add the "new string" at the "right side" of the path variable. But the "Cleanup" already helped me. Thank alot for sharing your knowledge...

      Thanks in Advance
      MH
Re: Trying to use [cpan://Win32::Env::Path] to change Windows Path Variable?
by bellaire (Hermit) on Nov 17, 2009 at 16:06 UTC
    Well, that's the synopsis for the module in question. Does it fail to meet your expectation of how it should work, and if so, in what way?

      Hmm. I am completely blind i think i dont understand how to get working code out of this? Some Help?

        You could start by telling us how it fails for you to do what you expect.

Re: Trying to use [cpan://Win32::Env::Path] to change Windows Path Variable?
by runrig (Abbot) on Nov 17, 2009 at 17:05 UTC
    This part of the documentation is very important:
    For the moment, the specifics of this class are remaining undocumentated.
    Please read the code for more information, API is subject to change.
    Because this is the code for the add method
    sub add { my $self = shift; my $path = shift; unless ( defined _STRING($path) ) { croak("Did not provide a path to ->add"); } die "CODE INCOMPLETE"; }
    The save method looks like it probably works. You can get the path add, add it on yourself, and then save() the result.
Re: Trying to use [cpan://Win32::Env::Path] to change Windows Path Variable?
by Marshall (Canon) on Nov 17, 2009 at 23:59 UTC
    If you want the Win32 command for looking at the environment variables:
    help set (typing just "set" does what "env" does
    help setlocal
    will give some info.
    The Windows command to see the path is "path".

    The Win32 command to append the path is: path = %PATH%;newdir

    I don't know why this module isn't working for you, but this "path=" command will work.

    I hope that it is clear that when you change the environment PATH variable like this, this only applies only as long as your program or shell that did this is running. The need for something like this is seldom. I am curious as to your application?

      Ok. Thank you. What i want to do is to change the path variable *permanently* and i would like it to do it with perl, since i have to edit some config files and i would like to do this in a single script, if possible I tried it already on the command line (on Win32 shell too, but it only affects the current shell environment ...)...