package resource: Fix Windows package detection (#2624)

Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com>
This commit is contained in:
Jerry Aldrich 2018-02-13 11:40:20 -06:00 committed by Jared Quick
parent 925c5bca8e
commit 7f0a39a76a

View file

@ -267,6 +267,12 @@ module Inspec::Resources
Select-Object -Property DisplayName,DisplayVersion | ConvertTo-Json Select-Object -Property DisplayName,DisplayVersion | ConvertTo-Json
EOF EOF
# We cannot rely on `exit_status` since PowerShell always exits 0 from the
# above command. Instead, if no package is found the output of the command
# will be `''` so we can use that to return `{}` to match the behavior of
# other package managers.
return {} if cmd.stdout == ''
begin begin
package = JSON.parse(cmd.stdout) package = JSON.parse(cmd.stdout)
rescue JSON::ParserError => e rescue JSON::ParserError => e