Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I tried copy and paste this to the command line but every newline is recognized as a new command start and not as part of the option:

"command -option:text
whatever"

between text and whatever is a newline which needs to be preserved.

Thanx in advance

share|improve this question
add comment

3 Answers

Use the ^ character as an escape:

command -option:text^

whatever

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
1  
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
1  
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
show 2 more comments

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
subprocess.call(["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
add comment

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
add comment

Your Answer

 
discard

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.