windows 如何检测如何在路径中转义空格

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/241634/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 11:31:53  来源:igfitidea点击:

How do I detect how to escape spaces in a path

windowsrubycygwin

提问by theschmitzer

In Cygwin a space in a path has to be escaped with a backslash Not true in Windows, put the whole path in a quote

在 Cygwin 中,路径中的空格必须用反斜杠转义 在 Windows 中不正确,将整个路径放在引号中

Is there a way to convert to this automatically in Ruby?

有没有办法在 Ruby 中自动转换为这个?

Otherwise, how in Ruby do I detect if I am running with Windows or Cygwin?

否则,如何在 Ruby 中检测我是使用 Windows 还是 Cygwin 运行?

回答by nobody

Quoting paths in Cygwin ought to work fine.

Cygwin 中的引用路径应该可以正常工作。

回答by knoopx

http://rant.rubyforge.org/

http://rant.rubyforge.org/

sys.escape("foo bar")
# gives on Windows: '"foo bar"'
# other systems: 'foo\ bar'

回答by theschmitzer

I found how to detect the platform at least - the RUBY_PLATFORM constant defines that.

我至少找到了如何检测平台 - RUBY_PLATFORM 常量定义了这一点。