20

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?

Cœur
  • 32,421
  • 21
  • 173
  • 232
randacun
  • 502
  • 1
  • 5
  • 17
  • Why do you need a multi-line? – Dor Cohen Aug 14 '12 at 07:57
  • Since I am passing a string, ^ character is not possible since it will be included in the string itself. I tried it, and it is still not working. – randacun Aug 14 '12 at 08:08
  • 8
    This really isn't a duplicate question, and it's completely valid. He's not asking about how to execute a multiline command, but rather how to push a string parameter that has more than one line. I'm in the same boat, I'm trying to call a program in a batch file. The ^ escapes the next line for command processing, but is passed to the program too where the syntax is invalid. – end-user Jul 17 '13 at 12:19
  • 3
    @end-user I voted to reopen. – Lime Feb 16 '15 at 19:40

3 Answers3

9

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
Community
  • 1
  • 1
Dor Cohen
  • 15,873
  • 22
  • 85
  • 152
  • 1
    If it's a duplicate vote to close or, if you have less than 3,000 rep, flag the question, don't answer. – ChrisF Aug 14 '12 at 08:04
  • 1
    Hi, I am passing a string parameter. If I add ^ character then it will be included in the input. – randacun Aug 14 '12 at 08:07
  • You have to terminate the string before the ^ character? In my case that is not possible because the multiline string command is generated by another program. So if it generates two lines of string, I can only add the opening and ending quotes at the very beginning and at the very end of the string parameter. – randacun Aug 14 '12 at 08:19
  • @randacun If you are accepting the parameters from another program so trim it to one line.. – Dor Cohen Aug 14 '12 at 08:23
  • We are using an IDE called uniPaaS which really lacks lot's of tools for string manipulation. Anyway, I think I might just find another solution like saving the actual string into a text file and passing the name of the text file instead of the string. Thanks for your answers. – randacun Aug 14 '12 at 08:54
  • 9
    I agree that this is NOT duplicate. I have the same problem and it infuriates me that someone (or some people in this case) who cannot understand the problem flag it as duplicate and take away from others option to have an answer. – yatsek Jan 05 '15 at 17:45
  • This method only works for two lines, as you can't (e.g.) use `"\Common Files" ^` to continue the string any further. – Mike T May 02 '17 at 01:23
  • This is not an answer to the OP's question. This addresses breaking lines outside of strings, rather than inside of strings, in CMD. – Leo Mar 30 '21 at 00:52
2

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
fcdt
  • 2,151
  • 5
  • 9
  • 24
  • Welcome to StackOverflow. I've added some code fences to your post so that a monospace font is used and the code is easier to recognize. You can also [edit] your post yourself if you still find errors. – fcdt Oct 08 '20 at 09:16
0

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 . . .
ilias
  • 123
  • 1
  • 9