Is there an equivalent to the Ruby Shellwords module for the Windows shell?
I need to construct Windows shell commandlines from arrays in Ruby. If I were using Bash, I could use the standard Shellwords module. Is there an equivalent to Shellwords for the Windows shell, which can safely transform a开发者_如何学Gon array to a commandline string?
It appears to me there is in fact no Windows analogue to Shellwords unfortunately.
I've settled on the following:
require 'os'
class String
def ~
if OS.windows?
return '"' + self.gsub('"', '""') + '"'
else
return self.shellescape
end
end
end
which allows me to shellescape any string by doing
~"some string with cruft&! in it"
This seems to be a version of shellwords with windows support: https://github.com/larskanis/shellwords
Not upstream yet as far as I see.
精彩评论