我想使用批处理文件中的eventcreate来记录文件复制作业(机器人副本)的结果。我真正想做的是使用文件复制作业的输出作为事件的描述(createevent的/D)。问题是,文件副本输出中有多行,而我只能将一行放入局部变量或管道命令中。
我试着从文件中读取局部变量,例如
set /P myVar=<temp.txt但它只得到第一行。
如何从批处理文件中将多行写入事件描述?
发布于 2010-04-30 20:23:41
您必须解析日志和更改和CRLF只有LF (Ctrl)。
下面是一个示例:
EVENTCREATE /T ERROR /ID 1000 /l application /d "This is text^L this is line 2"发布于 2020-05-14 13:00:57
您可以自己构建一个多线变量,称为!LF!。这文章详细解释了换行符/ CMD解析器是如何工作的。
@echo off
SETLOCAL EnableDelayedExpansion
(set LF=^
%=--------DO NOT remove this line. Expands to nothing--------=%
)
set "lines=" reset LINES to 0
set "in=temp.txt"
call :readlines "%in%" lines
<"%in%" (FOR /L %%# in (1 1 %lines%) do (
set "data=" ::clear DATA
set/p"data=" ::read from IN
set "fileContent=!fileContent!!data!!LF!" ::manually construct multi-line variable
)) %= read file by lines via SET /P =%
EVENTCREATE /T ERROR /ID 1000 /l application /d "!fileContent!"
exit /b
:readlines FILE VAR
FOR /F %%L in ('
"findstr /N "^^" "%~1" %= do not skip empty lines =%"
') do set/a"%~2+=1" %= Get the # of lines =%截图:

https://serverfault.com/questions/137493
复制相似问题