非常接近解决这个问题。
SET settings=D:\tomcat\conf\server.xml
FOR /F "eol=p tokens=1-2* delims==" %%A IN ('TYPE %settings% 2^> NUL ^| FINDSTR.exe /L /C:"\<Connector port\="') DO echo %%B
pause
Apache Tomcat通常在我们的Test / Prod / QA / Environments中的端口80上运行,但是我们在端口8080上有几个实例,并希望将端口解析为100%准确。
结果如下:
D:\WORK\Scripts\test>echo "80" protocol
"80" protocol
D:\WORK\Scripts\test>echo "8443" protocol
"8443" protocol
D:\WORK\Scripts\test>echo "8009" protocol
"8009" protocol
查看server.xml,我们(第一个是正确的):
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
以及(必须删除发布的评论) - 并被评论为“关闭”:
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
和
在端口8009上定义AJP 1.3连接器
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
并且..这是显示端口号的最终代码:
SET settings=D:\tomcat\conf\server.xml
FOR /F "eol=p tokens=1-2* delims==" %%A IN ('TYPE %settings% 2^> NUL ^| FINDSTR.exe /L /C:"\<Connector port\="') DO (
SET PORT=%%B
SET PORT=%PORT:" protocol=%
SET PORT=%PORT:"=%
goto :break
)
:break
pause
谢谢!
答案 0 :(得分:2)
@echo off
SET settings=D:\tomcat\conf\server.xml
FOR /F "eol=p tokens=1-2* delims==" %%A IN ('TYPE %settings% 2^> NUL ^| FINDSTR.exe /L /C:"\<Connector port\="') DO (
echo %%B
goto :break
)
:break
pause
如果第一个节点始终是正确的节点,则可以使用goto
中断for循环