模拟建了一个多行数据文件 a.txt (代表你要取的含有RUNNING字串的输出信息)
C:\TEMP\put>type a.txt
a
b
c
d
e
f
g
你看到上面 a.txt 有多行,最后一行是g。
直接在命令行取得 a.txt 多行内容并赋值给名为“变量”的一个变量。
C:\TEMP\put>for /f %i in (a.txt) do set 变量=%i
(仔细看:上面一行命令是执行。下面这些输出是上面for执行时的赋值过程:)
C:\TEMP\put>set 变量=a
C:\TEMP\put>set 变量=b
C:\TEMP\put>set 变量=c
C:\TEMP\put>set 变量=d
C:\TEMP\put>set 变量=e
C:\TEMP\put>set 变量=f
C:\TEMP\put>set 变量=g
你看到for执行时是依次将取得的a.txt内容赋给变量,
因为是多次赋值给同一个变量,所以最后一句: set 变量=g已经将前面赋的值都“冲了”,全被g这个字符给取代了。
C:\TEMP\put>echo %变量%
g
上面显示一下变量内容,结果是最后一次取得的内容: g
所以,你上面的for依次赋值得到的只能是最后一行的有效输出。
所以,for ...skip=跳过行数 可以解决部分固定输出行数不变的某个指定行的内容。
所以,if == 也可以解决非赋值的情况下直字串精确匹配查找%%i中是否拥有你要找的内容。
但,好象想起了你一次想判断Weblogic服务器是否正常正在运行时的标置的贴子,
如果此贴与如上所指的贴子有与判断weblogic服务器是否正常启动有关联的话,
那么你这么做在走很大的弯路。
Simulated to build a multi-line data file a.txt (representing the output information containing the string RUNNING that you want to retrieve)
C:\TEMP\put>type a.txt
a
b
c
d
e
f
g
You see that a.txt above has multiple lines, and the last line is g.
Directly obtain the multi-line content of a.txt on the command line and assign it to a variable named "variable".
C:\TEMP\put>for /f %i in (a.txt) do set 变量=%i
(Notice carefully: The above line of command is executed. The following outputs are the assignment process when the above for is executed:)
C:\TEMP\put>set 变量=a
C:\TEMP\put>set 变量=b
C:\TEMP\put>set 变量=c
C:\TEMP\put>set 变量=d
C:\TEMP\put>set 变量=e
C:\TEMP\put>set 变量=f
C:\TEMP\put>set 变量=g
You see that when the for is executed, it successively assigns the content obtained from a.txt to the variable.
Because it is assigned to the same variable multiple times, so the last sentence: set 变量=g has "erased" the previous assigned values, all replaced by the character g.
C:\TEMP\put>echo %变量%
g
The above shows the content of the variable, and the result is the last obtained content: g
So, the valid output you get from the for assignment in sequence is only the last line.
So, for ...skip=skipping lines can solve the content of a specified line when the number of fixed output lines remains unchanged.
So, if == can also solve the situation of accurately matching and finding whether the content you are looking for is in %%i without assignment.
But, it seems that I remember a post where you once wanted to judge whether the Weblogic server was running normally.
If this post is related to the post mentioned above regarding judging whether the Weblogic server starts normally,
then you are taking a very big detour by doing this.