Skip to content
This repository has been archived by the owner on Feb 19, 2019. It is now read-only.

[Enhancement] use chocolatey path on system without reboot #134

Closed
rismoney opened this issue Jul 28, 2012 · 12 comments
Closed

[Enhancement] use chocolatey path on system without reboot #134

rismoney opened this issue Jul 28, 2012 · 12 comments

Comments

@rismoney
Copy link
Contributor

With an assist from this - http://poshcode.org/2049... if an option is specified... thoughts?

user path currently is good, and minimal priveledges, etc...

@ferventcoder
Copy link
Contributor

WHAT?! That's awesome.

@rismoney
Copy link
Contributor Author

http://poshcode.org/3537

Going to test this one- 7 week's old...

@mwrock
Copy link
Contributor

mwrock commented Sep 14, 2012

I think rob and @Iristyle were looking at his yesterday and found that it did not work. I ran into this issue a couple weeks ago and also tried this without luck. Not sure if thats because powershell.exe does not subscribe to the broadcasts.

I did find however that this:

$paths=(Get-WmiObject Win32_Environment | where-object -filter {$_.Name -eq 'path'})
foreach($path in $paths) {$newPath += $path.VariableValue}
Write-Host $newPath

does work. It was mentioned though that "Path" may not be enough. There could be other variables that other programs might expect (like JAVA_HOME). Also, this needs to be batch file compliant as well. I believe @Iristyle was going to implement something that would work for both ps and dos. See the Issue #153 for the details of the discussion.

@rismoney
Copy link
Contributor Author

yea, i went to the authors website- http://mnaoumov.wordpress.com/2012/07/24/powershell-add-directory-to-environment-path-variable/ and right at the top, is his note...:( fail

@mwrock
Copy link
Contributor

mwrock commented Nov 4, 2012

This is still an open issue. The above pull request only fixes Chocolatey's ability to refresh its own view but does not refresh the view of the user session. Need to add some bath flavored means of refreshing a normal command line. Also need to provide a means of refreshing PS users most likely via their $Profile.

@ferventcoder
Copy link
Contributor

The initial workings for this are in b87541a - we'll see what other things crop up.

@AnthonyMastrean
Copy link
Contributor

I'm excited about this one, need it for some complicated packages that depend on the hg and 7zip command line packages first, to enable installing itself (hggit).

@ForNeVeR
Copy link

Hey, guys. What if I'm running chocolatey from the existing PowerShell session? It seems that PowerShell starts the new cmd process for the chocolatey.bat invocation, and your solution will instead refresh the environment only for the freshly started cmd and not the caller shell.

What can I do to refresh the caller PowerShell session environment? Maybe there should be an alternative C:\Chocolatey\bin\chocolatey.ps1 for such cases? What you think?

Ew, and then we have to reimplement the whole RefreshEnv.cmd with PowerShell. I still think it can be modified to construct the %TEMP%\_env.ps1 file with PowerShell syntax instead of %TEMP%\_env.bat with cmd syntax.

@ferventcoder
Copy link
Contributor

@ForNeVeR We already have the powershell refresh in and once the commands become aliases back to the module methods, you will see this happen automatically as there will be no call out to a batch and then back into powershell.

@ForNeVeR
Copy link

Thank you for response, that's a good news.

@ferventcoder
Copy link
Contributor

Fixed in a09e158

ferventcoder added a commit to ferventcoder/chocolatey that referenced this issue Jun 16, 2014
…md.exe

This adds a command RefreshEnv.cmd to the bin files, so that one can update
environment variables out of band. There is zero chance it will work once
chocolatey.cmd calls exit /b %ERRORLEVEL% as exiting the batch effectively
destroys any updates to local environmental changes. The way it currently
works is effectively the same as using setlocal due to the use of exit.

Since this command can be called out of band, it should be called out of
band, whenever the user wants to refresh their environment variables they
can call this. Note this only works in cmd.exe shell. There is no current way
to update a powershell session other than importing the helper functions as
a module and running Update-SessionEnvironment.
ferventcoder added a commit to ferventcoder/chocolatey that referenced this issue Jun 16, 2014
* stable:
  (chocolatey-archiveGH-460) Fix for "Package depending on newer chocolatey is installed using existing chocolatey"
  (chocolatey-archiveGH-459) Fix for "Cannot find Update-SessionInformation"
  (maint) formatting
  (chocolatey-archiveGH-153)(chocolatey-archiveGH-134) Update PATH on cmd.exe
  (maint) ensure powershell module loading preference is on
@ferventcoder
Copy link
Contributor

The current state is that unless you import the chocolateyinstaller module, you won't automatically get path updates. Importing the module isn't recommended at this time but some folks are experimenting with it.

With cmd.exe you can just call RefreshEnv after an install that would update something in your environment and it will update your session's environment.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants