Skip to content

Commit a45c8a7

Browse files
(FACT-3133) allow for echo on Windows
`echo` was supported for Windows in facter 3, but has been missing from support in facter 4; this change allows for custom facts to use the builtin echo commands in cmd.exe or powershell.
1 parent 13ccc8b commit a45c8a7

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/facter/custom_facts/core/execution/windows.rb

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ def search_paths
99
DEFAULT_COMMAND_EXTENSIONS = %w[.COM .EXE .BAT .CMD].freeze
1010

1111
def which(bin)
12+
# `echo` is allowed for facter 3.x compatibility, otherwise
13+
# all commands much be found on the PATH or absolute.
14+
return bin if /^echo$/i =~ bin
15+
1216
if absolute_path?(bin)
1317
return bin if File.executable?(bin)
1418
else

spec/custom_facts/core/execution/windows_spec.rb

+10
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@
3636
allow(ENV).to receive(:[]).with('PATHEXT').and_return nil
3737
end
3838

39+
context 'when trying to use builtin windows commands' do
40+
it 'allows echo' do
41+
expect(executor.which('echo')).to eq 'echo'
42+
end
43+
44+
it 'disallows other builtin windows commands' do
45+
expect(executor.which('dir')).to eq nil
46+
end
47+
end
48+
3949
context 'when it is provided with an absolute path' do
4050
it 'returns the path to binary if executable' do
4151
allow(File).to receive(:executable?).with('C:\Tools\foo.exe').and_return true

0 commit comments

Comments
 (0)