如何从批处理文件输出中插入换行符?
我想做的事情是:
echo hello\nworld
这将输出:
hello
world
如何从批处理文件输出中插入换行符?
我想做的事情是:
echo hello\nworld
这将输出:
hello
world
当前回答
在Ken的回答中添加一个变量,它显示了环境变量的设置值,其中包含新行。
我们使用此方法将错误条件附加到VAR中的字符串中,然后在所有错误检查输出的末尾将所有错误汇总到文件中。
这不是完整的代码,只是一个示例。
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
:: the two blank lines are required!
set NLM=^
set NL=^^^%NLM%%NLM%^%NLM%%NLM%
:: Example Usage:
Set ErrMsg=Start Reporting:
:: some logic here finds an error condition and appends the error report
set ErrMsg=!ErrMsg!!NL!Error Title1!NL!Description!NL!Summary!NL!
:: some logic here finds another error condition and appends the error report
set ErrMsg=!ErrMsg!!NL!Error Title2!NL!Description!NL!Summary!NL!
:: some logic here finds another error condition and appends the error report
set ErrMsg=!ErrMsg!!NL!Error Title3!NL!Description!NL!Summary!NL!
echo %ErrMsg%
pause
echo %ErrMsg% > MyLogFile.log
日志和屏幕输出看起来像这样…
其他回答
要批量地开始新一行,你所要做的就是添加“echo[”,像这样:
echo Hi!
echo[
echo Hello!
在Ken的回答中添加一个变量,它显示了环境变量的设置值,其中包含新行。
我们使用此方法将错误条件附加到VAR中的字符串中,然后在所有错误检查输出的末尾将所有错误汇总到文件中。
这不是完整的代码,只是一个示例。
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
:: the two blank lines are required!
set NLM=^
set NL=^^^%NLM%%NLM%^%NLM%%NLM%
:: Example Usage:
Set ErrMsg=Start Reporting:
:: some logic here finds an error condition and appends the error report
set ErrMsg=!ErrMsg!!NL!Error Title1!NL!Description!NL!Summary!NL!
:: some logic here finds another error condition and appends the error report
set ErrMsg=!ErrMsg!!NL!Error Title2!NL!Description!NL!Summary!NL!
:: some logic here finds another error condition and appends the error report
set ErrMsg=!ErrMsg!!NL!Error Title3!NL!Description!NL!Summary!NL!
echo %ErrMsg%
pause
echo %ErrMsg% > MyLogFile.log
日志和屏幕输出看起来像这样…
Use:
echo hello
echo:
echo world
在windows 10的虚拟终端序列中,存在高度控制光标位置的方法。
要定义转义序列0x1b,可以使用以下方法:
@Echo off
For /f %%a in ('echo prompt $E^| cmd')Do set \E=%%a
在字符串之间输出一个换行符:
<nul set /p "=Hello%\E%[EWorld"
输出n个换行符,其中n被整数替换。
<nul set /p "=%\E%[nE"
Many
就像Grimtron建议的那样-这里有一个简单的例子来定义它:
@echo off
set newline=^& echo.
echo hello %newline%world
输出
C:\>test.bat
hello
world