我需要從Ruby中的數組構建Windows shell命令行。如果我使用Bash,我可以使用標準的Shellwords模塊。是否有相當於Windows Shell的Shellwords,它可以安全地將數組轉換爲命令行字符串?是否有相當於Windows Shell的Ruby Shellwords模塊?
3
A
回答
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"
1
這似乎是一個版本shellwords的Windows支持到shellescape任何字符串: https://github.com/larskanis/shellwords
據我所知,尚未上游。
相關問題
- 1. 是否有.bat相當於shell選擇?
- 2. Ruby,Log4Ruby是否有相當於Log4J的?
- 3. 是否有與Ruby ruby相當的CoffeeScript?
- 4. JavaScript/CoffeeScript相當於Ruby Timeout模塊
- 5. 是否有一個相當於python的optparse.OptionParser的perl模塊?
- 6. 是否有一個相當於將在Windows上安裝的node-png模塊?
- 7. 是否有相當於IIS的mod_pagespeed Apache模塊?
- 8. 是否有相當於python的bootstrap.php?
- 9. php是否有相當於python的virtualenv或ruby的沙箱?
- 10. 是否有與Java MessageFormat相當的Ruby?
- 11. 是否有與eventfd相當的Windows?
- 12. 是否有sprintf相當於node.js
- 13. 是否有相當於Django Model.objects.filter()的CherryPy?
- 14. Ember是否具有相當於ruby的method_missing?
- 15. 是否有相當於Node.js(雲存儲API)的ruby Fog Gem?
- 16. 是否有相當於to_yaml_properties的Ruby檢查?
- 17. 是否有相當於wp7的windows 8/winrt/metro風格的marketplacereviewtask?
- 18. 在Windows上是否有相當於sbrk(0)的問題
- 19. 在Windows中是否有用於Perl 5.14的Socket6 0.23模塊?
- 20. 是否有適用於Windows 7 64位的Python藍牙模塊?
- 21. 是否有相當於$ sformat的函數?
- 22. 是否有相當於webforms的T4MVC?
- 23. PHP是否有相當於Java的RequestDispatcher.forward?
- 24. 是否有相當於OS X的lsusb
- 25. 是否有相當於MATLAB的igraph?
- 26. 是否有相當於Java的Boost :: Python?
- 27. 是否有相當於$ {LIB}的dyld?
- 28. 是否有相當於c#中的typedef?
- 29. 是否有相當於os.Args()的函數?
- 30. Sencha是否有相當於jQuery的Radioset?
需要注意的是'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