Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to execute a command on cmd.exe, with a line break or new line as part of the command, like below:

command -option:text  

But every new line executes the command, instead of continuing the command on the next line.

So how can I input a new line character, or create a multi-line command in cmd.exe?

share|improve this question

Use the ^ character as an escape:

command -option:text^


I'm assuming you're using cmd.exe from Windows XP or similar. This is not actual DOS. If you are using actual DOS (MS-DOS, Win3.1, Win95, Win98, WinME), then I do not believe there is an escape for newlines. You would need to run a custom shell. cmd.exe will prompt you for "More?" each time you press enter with a ^ at the end of the line, just press enter again to actually escape/embed a newline.

share|improve this answer
Too cool, I did not know that. – T.J. Crowder Jun 8 '10 at 10:05
This what you suggests is the allows me to enter more text on a newline. It does not preserve the newline. What i want is that between "text" and "whatever" is an newline. Something like this: "text\nwhatever" – rudimenter Jun 8 '10 at 10:09
I believe you have to use two newlines to do that, my bad for not realizing this in my original post (now edited) – Darth Android Jun 8 '10 at 19:17
@T.J. Crowder I know, I didn't either until I looked it up for another question on here a few days ago. – Darth Android Jun 8 '10 at 19:23
It should be noted that if you have spaces in the text, you will need to wrap them in quotes. Further, make sure that you include the end quote, otherwise the caret will be ignored as an escape character and treated like text. Finally, you will need to put quotes around the text on each line containing spaces (do so even if it doesn't contain spaces to be safe), and put a caret after the closing quote for each line that continues. – Synetech Jan 28 '11 at 5:40

I don't know if this will work for you but by putting &echo (the following space is important). in between each statement that you want on a new line. I only tried this with a simple bat file of

echo %1

Then saved that as testNewLines.bat

So then the cmd line

testNewLines first line&echo Second Line&echo Third line

Resulted in the following being echoed back

first line
second line
Third line

share|improve this answer

I believe you can't do that from the Windows cmd.exe shell. (It is not DOS.)

You do not need a full "custom shell" for that. You will only need to write something like this (example in Python):

import subprocess["C:\\bin\\sometool.exe", "test\nwith\nnewlines"])

Or Ruby:

Kernel::exec "C:\\bin\\sometool.exe", "test\nwith\nnewlines"

See, it's not that hard.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.