Skip to content

Commit 988ee0f

Browse files
Merge pull request #312 from chef/sanjain/CHEF-25203/fix/chef-exec-env-windows
CHEF-25203: Fix chef exec and env command not working in Windows
2 parents 344b4ec + 8c2bf29 commit 988ee0f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/chef-cli/helpers.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ def omnibus_env
210210
end
211211

212212
def get_pkg_prefix(pkg_name)
213-
path = `hab pkg path #{pkg_name} 2>/dev/null`.strip
213+
stderr_redirect = Chef::Platform.windows? ? "2>NUL" : "2>/dev/null"
214+
path = `hab pkg path #{pkg_name} #{stderr_redirect}`.strip
214215
path if !path.empty? && Dir.exist?(path) # Return path only if it exists
215216
end
216217

@@ -265,7 +266,8 @@ def macos?
265266
# @api private
266267
#
267268
def hab_pkg_installed?(pkg_name)
268-
`hab pkg list #{pkg_name} 2>/dev/null`.include?(pkg_name) rescue false
269+
stderr_redirect = Chef::Platform.windows? ? "2>NUL" : "2>/dev/null"
270+
`hab pkg list #{pkg_name} #{stderr_redirect}`.include?(pkg_name) rescue false
269271
end
270272
end
271273
end

0 commit comments

Comments
 (0)