Skip to content

Commit

Permalink
Port to winrm v2.
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasvan committed Oct 28, 2016
1 parent 7fd5e52 commit fe42b1c
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions lib/specinfra/backend/winrm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@ def run_command(cmd, opts={})
script = create_script(cmd)
winrm = get_config(:winrm)

result = winrm.powershell(script)
stdout, stderr = [:stdout, :stderr].map do |s|
result[:data].select {|item| item.key? s}.map {|item| item[s]}.join
end
result[:exitcode] = 1 if result[:exitcode] == 0 and !stderr.empty?
winrm.shell(:powershell) do |shell|
result = shell.run(script)
stdout = result.stdout.to_s
stderr = result.stderr.to_s

if @example
@example.metadata[:command] = script
@example.metadata[:stdout] = stdout + stderr
end
result.exitcode = 1 if result.exitcode == 0 and !stderr.empty?

CommandResult.new :stdout => stdout, :stderr => stderr, :exit_status => result[:exitcode]
if @example
@example.metadata[:command] = script
@example.metadata[:stdout] = stdout + stderr
end

CommandResult.new :stdout => stdout, :stderr => stderr, :exit_status => result.exitcode
end
end
end
end
Expand Down

0 comments on commit fe42b1c

Please sign in to comment.