2

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?

falsetru
  • 314,667
  • 49
  • 610
  • 551
Ed Limonov
  • 105
  • 1
  • 6
  • 1
    Possibly helpful: https://stackoverflow.com/questions/132799/how-can-you-echo-a-newline-in-batch-files – bbozo Dec 24 '15 at 14:13

1 Answers1

4

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"
falsetru
  • 314,667
  • 49
  • 610
  • 551