Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding windows path via perl

Status
Not open for further replies.

jr8rdt

IS-IT--Management
Feb 9, 2006
59
US
I would like add path to windows using perl
"set path=%path%;c:\data"

so I have tried all these below without success:

1)
$a = `set path=%path%;c:\\utils`;
print $a;

2)
system("set path=%path%;c:\\utils");

can anybody help. what I did wrong ?
can anybody help? thanks in advance for your help.
 
I believe you use the SET command to update the "set path" path in Windows. Google for "Windows set path".

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
I don't think that the path variable is going to stay once the command session is closed.

Code:
@path = `path`;
print "@path\n";

@path = `set path=\%path\%;c:\\utils && path`;
print "@path\n";

@path = `path`;
print "@path\n";

Notice how it's not there.. then it's there.. then it's gone again.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
I don't think that the path variable is going to stay once the command session is closed."


so there is no way we can set windows path using perl ? I know I can modify the registry using perl to set the path. But that requires reboot.

I need to add the path using perl which 1)permanent 2) available (take effect) immidiately.

so I come up with doing those 2 in the perl

using TieRegistry

$Registry->{"HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Session Manager/Environment/Path"} = $pathCheck . ";c:\\utils";
system 'set path=%path%;c:\\utils';

the registry works but not the set path.

so the only other alternative is to load the registry. how ?

 
What is the reason you are trying to change the path? Are you sure it's not something you can work around?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
it is for automation of hundreds of remote production servers. if not perl, what is the alternative?
 
Is setting the path the only thing you want to do? If so just do it in the registry and reboot the box. It will take affect then. I think if it's in the registry the next command session open will have it. If you are trying to do additional work you should explain exactly what you are trying to do.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
It's possible with SETX utility without the need of registry edit and without computer restart. The SETX utility is a part of Windows XP Service Pack 2 Support Tools .
On the Windows Vista it's available automatically, because I never installed it.

For example: Now I'm on Windows Vista Home Basic and I have this utility available too.
My current path is
Code:
Path=C:\Python25\;C:\Tcl\bin;C:\Program Files\MiKTeX 2.7\miktex\bin;c:\ruby\bin;C:\Perl\site\bin;C:\Perl\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files\ooRexx;C:\Program Files\Regina;C:\Python25\;C:\Tcl\bin;C:\Program Files\MiKTeX 2.7\miktex\bin;c:\ruby\bin;C:\Perl\site\bin;C:\Perl\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files\ooRexx;C:\Program Files\Regina;C:\Program Files\Groovy\Groovy-1.5.6\bin;C:\Program Files\clisp-2.44;C:\Program Files\PLT;c:\Program Files\Java\jdk1.6.0_11\bin;C:\Program Files\4tH;C:\msys\1.0\mingw\bin;C:\msys\1.0\mingw\lib\gcc-lib\i686-pc-mingw32\4.0.4;C:\Program Files\gfortran\libexec\gcc\i586-pc-mingw32\4.4.0;C:\Program Files\gfortran\bin
After I execute this command
Code:
C:\Users\Roman>setx path "%path%";something_new

SUCCESS: Specified value was saved.
and then I call the new instance of Command Line I see that something_new was added to the path:
Code:
Path=C:\Python25\;C:\Tcl\bin;C:\Program Files\MiKTeX 2.7\miktex\bin;c:\ruby\bin;C:\Perl\site\bin;C:\Perl\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files\ooRexx;C:\Program Files\Regina;C:\Python25\;C:\Tcl\bin;C:\Program Files\MiKTeX 2.7\miktex\bin;c:\ruby\bin;C:\Perl\site\bin;C:\Perl\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files\ooRexx;C:\Program Files\Regina;C:\Python25\;C:\Tcl\bin;C:\Program Files\MiKTeX 2.7\miktex\bin;c:\ruby\bin;C:\Perl\site\bin;C:\Perl\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files\ooRexx;C:\Program Files\Regina;C:\Program Files\Groovy\Groovy-1.5.6\bin;C:\Program Files\clisp-2.44;C:\Program Files\PLT;c:\Program Files\Java\jdk1.6.0_11\bin;C:\Program Files\4tH;C:\msys\1.0\mingw\bin;C:\msys\1.0\mingw\lib\gcc-lib\i686-pc-mingw32\4.0.4;C:\Program Files\gfortran\libexec\gcc\i586-pc-mingw32\4.4.0;C:\Program Files\gfortran\bin;[COLOR=red]something_new[/color]

When I now click on My Computer/Properties/Environment Variables then something_new is now in my user environment path.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top