Updating PATH on windows for use in subsequent recipes

Hi

Is there a way to force reload of the PATH variable on windows?

We install git & nodejs and then tries to install some npm packages from a
git repo.

But in the initial run, npm cannot find git because the current process’
PATH is not updated.

Starting a new shell and running chef-client solves the issue, but this is
of course less than ideal.

Any ideas?

/Jeppe

How are you updating the path – using the env resource? On Windows, env
sends a broadcast system message message that should cause new processes to
get the latest environment.

-Adam

From: Jeppe Nejsum Madsen [mailto:jeppe@ingolfs.dk]
Sent: Monday, May 19, 2014 10:46 AM
To: chef@lists.opscode.com
Subject: [chef] Updating PATH on windows for use in subsequent recipes

Hi

Is there a way to force reload of the PATH variable on windows?

We install git & nodejs and then tries to install some npm packages from a
git repo.

But in the initial run, npm cannot find git because the current process’
PATH is not updated.

Starting a new shell and running chef-client solves the issue, but this is
of course less than ideal.

Any ideas?

/Jeppe

We do it in the 'php' cookbook like this:

  • Julian

On Mon, May 19, 2014 at 1:46 PM, Jeppe Nejsum Madsen jeppe@ingolfs.dk wrote:

Hi

Is there a way to force reload of the PATH variable on windows?

We install git & nodejs and then tries to install some npm packages from a
git repo.

But in the initial run, npm cannot find git because the current process'
PATH is not updated.

Starting a new shell and running chef-client solves the issue, but this is
of course less than ideal.

Any ideas?

/Jeppe

--
[ Julian C. Dunn jdunn@aquezada.com * Sorry, I'm ]
[ WWW: http://www.aquezada.com/staff/julian * only Web 1.0 ]
[ gopher://sdf.org/1/users/keymaker/ * compliant! ]
[ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9 ]

This is how we do it. its in our base recipe for windows :slight_smile:

powershell_script "Add path to appcmd to Environment PATH" do
code <<-EOB
$PathToAdd = "%windir%\system32\inetsrv"
$VerifiedPathsToAdd = $null
Foreach($Path in $PathToAdd) {
if($env:Path -like "$Path") {
}
else {
$VerifiedPathsToAdd += ";$Path"
}
if($VerifiedPathsToAdd -ne $null) {
[Environment]::SetEnvironmentVariable("Path",$env:Path +
$VerifiedPathsToAdd,"Machine")
}
}
EOB
end

On Mon, May 19, 2014 at 11:19 PM, Julian C. Dunn jdunn@aquezada.com wrote:

We do it in the 'php' cookbook like this:

https://github.com/opscode-cookbooks/php/blob/master/recipes/package.rb#L54-L55

  • Julian

On Mon, May 19, 2014 at 1:46 PM, Jeppe Nejsum Madsen jeppe@ingolfs.dk
wrote:

Hi

Is there a way to force reload of the PATH variable on windows?

We install git & nodejs and then tries to install some npm packages from
a
git repo.

But in the initial run, npm cannot find git because the current process'
PATH is not updated.

Starting a new shell and running chef-client solves the issue, but this
is
of course less than ideal.

Any ideas?

/Jeppe

--
[ Julian C. Dunn jdunn@aquezada.com * Sorry, I'm ]
[ WWW: http://www.aquezada.com/staff/julian * only Web 1.0 ]
[ gopher://sdf.org/1/users/keymaker/ * compliant! ]
[ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9 ]