Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/winrm/winrm_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,12 @@ def run_command(shell_id, command, arguments = [], cmd_opts = {})
s.input = "#{NS_WIN_SHELL}:CommandLine"
s.body = { "#{NS_WIN_SHELL}:Command" => "\"#{command}\"", "#{NS_WIN_SHELL}:Arguments" => arguments}

resp = send_message(s.to_xml)
# Grab the command element and unescape any single quotes - issue 69
xml = s.to_xml
escaped_cmd = /<#{NS_WIN_SHELL}:Command>(.+)<\/#{NS_WIN_SHELL}:Command>/.match(xml)[1]
xml.sub!(escaped_cmd, escaped_cmd.gsub(/&#39;/, "'"))

resp = send_message(xml)
(resp/"//#{NS_WIN_SHELL}:CommandId").text
end

Expand Down
21 changes: 16 additions & 5 deletions test/spec/cmd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,32 @@

it 'should run a CMD command string' do
output = @winrm.run_cmd('ipconfig /all')
output[:exitcode].should == 0
output[:data].should_not be_empty
expect(output[:exitcode]).to eq(0)
expect(output[:data]).to_not be_empty
end

it 'should run a CMD command with proper arguments' do
output = @winrm.run_cmd('ipconfig', %w{/all})
output[:exitcode].should == 0
output[:data].should_not be_empty
expect(output[:exitcode]).to eq(0)
expect(output[:data]).to_not be_empty
end

it 'should run a CMD command with block' do
outvar = ''
@winrm.run_cmd('ipconfig', %w{/all}) do |stdout, stderr|
outvar << stdout
end
outvar.should =~ /Windows IP Configuration/
expect(outvar).to match(/Windows IP Configuration/)
end

it 'should run a CMD command that contains an apostrophe' do
output = @winrm.run_cmd(%q{echo 'hello world'})
expect(output[:exitcode]).to eq(0)
expect(output[:data][0][:stdout]).to match(/'hello world'/)
end

it 'should run a CMD command that is empty' do
output = @winrm.run_cmd('')
expect(output[:exitcode]).to eq(0)
end
end