30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/knife/dsl.rb', line 30
def knife_capture(command, args=[], input=nil)
null = Gem.win_platform? ? File.open('NUL:', 'r') : File.open('/dev/null', 'r')
warn = $VERBOSE
$VERBOSE = nil
stderr, stdout, stdin = STDERR, STDOUT, STDIN
Object.const_set("STDERR", StringIO.new('', 'r+'))
Object.const_set("STDOUT", StringIO.new('', 'r+'))
Object.const_set("STDIN", input ? StringIO.new(input, 'r') : null)
$VERBOSE = warn
status = Chef::Knife::DSL::Support.run_knife(command, args)
return STDOUT.string, STDERR.string, status
ensure
warn = $VERBOSE
$VERBOSE = nil
Object.const_set("STDERR", stderr)
Object.const_set("STDOUT", stdout)
Object.const_set("STDIN", stdin)
$VERBOSE = warn
null.close
end
|