简体   繁体   English

Windows中的Ruby多行反引号exec不起作用

[英]Ruby multi-line backtick exec in Windows doesn't work

This is what I'm doing: 这就是我在做什么:

cmd = "echo foo\n echo bar"
out = `#{cmd}`

In Linux I have "foo\\nbar". 在Linux中,我有“ foo \\ nbar”。 In Windows I have "foo". 在Windows中,我有“ foo”。 Why is that? 这是为什么? How to fix? 怎么修?

It seems like cmd.exe read until the newline ( \\n ) and ignore remaining part. 似乎cmd.exe读取直到换行符( \\n ),然后忽略其余部分。

You can use && instead to combine to commands: 您可以使用&&代替合并到命令:

cmd = "echo foo && echo bar"
out = `#{cmd}`
# => "foo \nbar\n"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM