-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to send commands containing apostrophe characters #69
Comments
Try this: In some cases to run Windows DOS and Powershell commands using WInRM can get really complicated, but it works great for all the cases I have tried so far. |
@rinat-io, The command syntax can indeed get tricky! :) I have no problem when using winrs, but only with the winrm gem. The event log output in my original post shows that the xml that is received by the server contains I'm curious, what version of Windows did you send your example commands to? Also, would you mind posting a small snippet of your ruby script where you got this to work? I may have misinterpreted something in your post, but I cannot get the commands you posted to work for me in any form, whether I directly enter them at a command prompt, send them to a server with winrs, or send them to a server with the winrm gem. The only form that did execute actually echoed the slash characters, which is not what I want. |
@keiths-osc , yes it is very tricky and needs some time to get use to it.
Result
I run framework that has WinRM gem integrated into it with both Windows Server 2008 & Windows Server 2012 and it works fine. There were some minor differences between those two OS types, but I have added some exceptions handling in my libraries and have forgotten when I did RDP to my hosts for those tasks that have been automated :) |
@rinat-io, Thanks for posting your example. When I run your example (with the correct hostname, port, etc), I get the exact same error that I originally posted. I believe that the command text in your example is identical to my original example. The only difference between your example and mine is a bit of ruby syntax. For example, this script:
produces this output:
The slash characters are not actually in the string you are sending to the server, and if you remove them from your example, you should find that it makes no difference. There are two possibilities I see for why you aren't getting the same error as me: 1) You are using a different version of the winrm gem or one of its dependencies which actually sends |
@keiths-osc it is very interesting, to say the least :)
And I'm running it with Ruby 1.9.3 on Linux Ubuntu 12.04 LTS
I just run the same snippet with Windows Server 2012 and here how that command looks like in analytic log:
I hope that helps. |
@rinat-io, that was extremely helpful! The analytic log shows that the apostrophe characters were not encoded at all. I think have determined what's going on. The winrm gem uses gyoku (via savon) to build the xml strings that ultimately get sent to the server. Gyoko, on this line, uses ruby's This script:
produces this output on Ruby 1.9.3:
but this output on Ruby 2.0:
So, it appears that this issue will only manifest itself on Ruby 2.0 or higher. |
You are welcome @keiths-osc and thank you very much for figuring out all the differences. |
Fixed by #73 |
It doesn't appear to be possible to use the winrm gem to send any commands that contain an apostrophe character.
For example, this script:
prints the following output:
(Note that this command is just a sample to demonstrate the problem. The echo command doesn't need the single quotes, but there are commands that do, such as a for loop that is processing the output of a command).
If you directly run the same command in a command prompt, or if you use winrs to send the command to the server, then the command works fine.
For example:
Produces:
I did a little bit of digging, and the problem appears to be that the winrm web service doesn't like the
'
(despite the fact that it is perfectly valid xml). To prove it, I first enabled the analytic log as described here. In the log, you can see the xml payload that was received by the server. Here is a snippet of one of the log messages that shows what the server actually received from the example script:If you enter the command
echo 'hello world'
at a command prompt in windows, you get the exact same output that was displayed by the above ruby script.When looking at the analytic log after using winrs to send the same command, I noticed that it escaped the apostrophe characters by using
'
instead of'
. If I modify this line in my locally installed copy of the winrm gem to replace any'
characters with'
and then run the sample script again, I get the expected output. (I considered just sending a pull request that simply does the replace on that line, but I'm not sure it's the best solution to the problem. If someone were legitimately trying to send the text'
as part of some command, it would be replaced with'
).I noticed that there is a "working" branch in this repository that appears to have pretty drastically changed how the soap messages get built. I repeated the test using the code from the working branch, but it appears that it also sends
'
instead of'
.The server I was sending winrm commands to was running Windows Server 2008 R2 SP1.
The text was updated successfully, but these errors were encountered: