2011-04-12 32 views

回答

1

在我看來,實際上沒有任何Windows類似Shellwords的不幸之處。

1

我已經談妥了以下幾點:

require 'os' 
class String 
    def ~ 
    if OS.windows? 
     return '"' + self.gsub('"', '""') + '"' 
    else 
     return self.shellescape 
    end 
    end 
end 

,讓我做

~"some string with cruft&! in it" 
+0

需要注意的是'os'來自os gem,可以在這裏找到:https://github.com/rdp/os - 雖然不是一個大問題,但它確實增加了依賴關係。這裏有這個問題討論Windows檢測:http://stackoverflow.com/questions/4871309/what-is-the-correct-way-to-detect-if-ruby-is-running-on-windows – amenthes 2015-03-24 22:01:32

相關問題