Ed Limonov
Ed Limonov

Reputation: 105

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". In Windows I have "foo". Why is that? How to fix?

Upvotes: 2

Views: 125

Answers (1)

falsetru
falsetru

Reputation: 369424

It seems like cmd.exe read until the newline (\n) and ignore remaining part.

You can use && instead to combine to commands:

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

Upvotes: 4

Related Questions