0

When I invoke powershell with the -c command line parameter and a write-output "foo bar" command, the words are printed on separate lines:

PS> powershell -c 'write-output "foo bar"' 
foo
bar

When I execute the following line, it prints both words on the same line, which is what I expected for the above command as well:

powershell -c 'cmd /c echo foo bar'
foo bar

I don't understand what makes the word printed on separate lines.

René Nyffenegger
  • 39,402
  • 33
  • 158
  • 293
  • 1
    https://stackoverflow.com/questions/68136128/how-do-i-call-the-powershell-cli-robustly-with-respect-to-character-encoding-i search for `-Command`: _"but in the end PowerShell simply joins them together with spaces, after having stripped (unescaped) double quotes on Windows, before interpreting the resulting string as PowerShell code"_. You would just need to double down on the double quotes on your first example. – Santiago Squarzon Jan 24 '22 at 14:14

1 Answers1

0

As Santiago Squarzon said, this should work in Powershell

PS> powershell -c "write-output 'foo bar'"
foo bar
DSSO21
  • 109
  • 9