Q. How can I write a long command, over multiple lines, in either the command prompt window or a batch file?

A. The Windows command prompt (cmd.exe) allows the ^ (Shift + 6) character to be used to indicate line continuation. It can be used both from the normal command prompt (which will actually prompt the user for more input if used) and within a batch file.

Below is an example of the character used in a command prompt (although it could easily have fit on one line):

D:\Temp>copy ^
       

More?a.a ^

More?b.b

1 file(s) copied.

I could place the same content in a batch file, and interestingly, when it’s run, it automatically puts the multiple lines onto a single line. For example, if my batch file contains the following:

copy ^
a.a ^
b.b

when I run it, I see the following on screen, which shows the command on one line:

<>D:\Temp>@badcopy.bat
       

D:\Temp>copy a.a b.b

1 file(s) copied.

Please or Register to post comments.

Upcoming Training

Mastering System Center 2012

During over 6 hours of training you can join John Savill from your computer as he will walk you through the key components and capabilities of System Center 2012, what’s involved in using the components, and the benefit they can bring to your environment.

Register Now

Current Issue

May 2013 - The NameTranslate object is useful when you need to translate Active Directory object names between different formats, but it's awkward to use from PowerShell. Here's a PowerShell script that eliminates the awkwardness.

CURRENT ISSUE / ARCHIVE / SUBSCRIBE

Windows Forums

Get answers to questions, share tips, and engage with the Windows Community in our Forums.