简体   繁体   中英

Windows Command Prompt: How to pass multi-line string parameters

I have a program that accepts a string parameter. I create a batch file that executes the program and a multiline string paramter. I also have a second parameter after the multiline string.

C:\>MyProgram "This is a
multiline text" parameter2

When I run this, only the first line of string is included in the command and the subsequent lines and the second parameter are ignored. Is there any way to pass multiline string parameters?

Your question is duplicate to - Windows: How to specify multiline command on command prompt?

In the Windows Command Prompt the ^ is used to escape the next character on the command line.

For example, (the More? being a prompt):

C:\>cd "c:\Program Files" ^
More? "\Common Files"

C:\>MyProgram "This is a " ^  
More? "multiline text" parameter2

This routine will write multiple lines to text file ASM.txt in the drive and directory of F:\\Backup_Info . Note that it will give a line space using the space then ^ symbol as shown, a line space is required between each statement:

(echo To Do is to Understand^

Who Dares Wins^

 ^

Baz) > F:\Backup_Info\ASM.txt

You can save ^ 's output as a variable

set br= ^
<</br (newline)>>
<</br>>

example:

@echo off
setlocal enableExtensions enableDelayedExpansion
rem cd /D "%~dp0"
set br= ^


rem br, can't be saved to a var. by using %..%;


set "t=t1!br!t2!br!t3"

for /f "usebackq tokens=* delims=" %%q in ('!t!') do (
    echo %%q
)


:scIn
rem endlocal
pause
rem exit /b

; output:

t1
t2
t3
Press any key to continue . . .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM