简体   繁体   English

Windows 命令提示符:如何传递多行字符串参数

[英]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?您的问题与 - Windows:如何在命令提示符下指定多行命令重复

In the Windows Command Prompt the ^ is used to escape the next character on the command line.在 Windows 命令提示符中,^ 用于转义命令行上的下一个字符。

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 .此例程将多行写入F:\\Backup_Info驱动器和目录中的文本文件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 . . .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用带有一些多行文本的命令提示符在Windows中创建文件? - How to create a file in windows using command prompt with some multi-line text? 多行命令提示符命令 - Multi-line Command Prompt Command 如何将多行命令行命令复制/粘贴到命令提示符中? - How to copy/paste multi-line command line command into Command Prompt? 在Windows中使用curl命令提示如何执行多行命令? - Using curl command in Windows prompt how to execute multi line command? 将多行字符串作为参数传递给Windows中的脚本 - Passing a multi-line string as an argument to a script in Windows 在Windows的命令提示符中使用start命令执行程序时,如何将多个参数传递给程序? - How to pass multiple parameters to a program while executing it using start command in command prompt in windows? 如何从Windows命令行将参数传递给node.js - How to pass parameters to node.js from Windows command line 如何将命令的多行 output 存储到批处理变量中? - How to store a command's multi-line output to a batch variable? 如何在 for /f 循环中处理多行命令? - How to process a multi-line command inside of a for /f loop? 如何将参数从 Windows 命令提示符传递到 Kitchen.bat (Pentaho)? - How can I pass parameters from Windows command prompt to Kitchen.bat (Pentaho)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM