Class: Specinfra::Backend::Cmd
Instance Method Summary
collapse
#add_pre_command, #build_command, #check_running, #create_script, #encode_script
Methods inherited from Base
clear, #command, #get_config, #host_inventory, #initialize, instance, #set_config, #set_example, #stderr_handler=, #stdout_handler=
Instance Method Details
#check_os ⇒ Object
44
45
46
47
|
# File 'lib/specinfra/backend/cmd.rb', line 44
def check_os
'Windows'
end
|
#execute_script(script) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/specinfra/backend/cmd.rb', line 31
def execute_script script
if Open3.respond_to? :capture3
stdout, stderr, status = Open3.capture3(script)
status = 1 if status == 0 and !stderr.empty?
{ :stdout => stdout, :stderr => stderr, :status => status }
else
stdout = `#{script} 2>&1`
{ :stdout => stdout, :stderr => nil, :status => $? }
end
end
|
#os_info ⇒ Object
8
9
10
|
# File 'lib/specinfra/backend/cmd.rb', line 8
def os_info
{ :family => 'windows', :release => nil, :arch => nil, :cygwin => `echo $0`.include?("sh") }
end
|
#run_command(cmd, opts = {}) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/specinfra/backend/cmd.rb', line 12
def run_command(cmd, opts={})
script = create_script(cmd)
psh = powershell
if os_info[:cygwin]
psh.gsub!("\\", "/")
psh.sub!(":", "")
psh = psh.prepend("/cygdrive/")
end
result = execute_script %Q{#{psh} -NoProfile -encodedCommand #{encode_script(script)}}
if @example
@example.metadata[:command] = script
@example.metadata[:stdout] = result[:stdout] + result[:stderr]
end
CommandResult.new :stdout => result[:stdout], :stderr => result[:stderr],
:exit_status => result[:status]
end
|