@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
set freePort=
set newPort=
REM Checking the default value in XML file located at the path
FOR /F tokens^=4^ delims^=^" %%A in (
'type %~dp0\wlp\usr\servers\defaultServer\server.xml ^| find "httpEndpoint host="'
) do (
echo: Default Port in XML = %%A
set /a startPort=%%A
)
echo myCurrent port %startPort%
:SEARCHPORT
netstat -o -n -a | find "LISTENING" | find ":%startPort% " > NUL
if "%ERRORLEVEL%" equ "0" (
echo "port unavailable %startPort%"
REM Here I want to ask user to enter a port number rather than hard-coded value ???
set /a startPort=9080
echo myNew port %startPort%
GOTO :SEARCHPORT
) ELSE (
echo "port available %startPort%"
set freePort=%startPort%
GOTO :FOUNDPORT
)
:FOUNDPORT
echo free %freePort%
REM here I want to change the value of the httpPort in XML and save the xml file, and then launch the default browser with https:\\localhost:<freePort>MyApp ???
)
@pause
은 server.xml 내용은 다음과 같습니다 Windows 명령 인터프리터와 XML 파일을 처리사용자로부터 가치를 받아 XML 파일의 특정 값을 변경하고 브라우저를 시작하는 방법은 무엇입니까?
이<server description="new server">
<!-- Enable features -->
<featureManager>
<feature>webProfile-7.0</feature>
<!-- <feature>localConnector-1.0</feature> -->
</featureManager>
<!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
<httpEndpoint host="27" httpPort="5357" httpsPort="9443" id="defaultHttpEndpoint"/>
<!-- Automatically expand WAR files and EAR files -->
<applicationManager autoExpand="true"/>
<applicationMonitor updateTrigger="mbean"/>
기본적으로 XML 파일을 읽고 쓸 수있는 스크립팅 언어를 사용하는 것이 좋습니다. Powershell, Vbscript 또는 Jscript는 몇 가지 옵션입니다. 배치 파일이이를 수행하려면 무차별 대입 (brute force)을 사용해야합니다. – Squashman
거의 완료되었습니다. 배치 스크립트의 xml 파일에 httpPort = "< >"의 새 값을 넣기 만하면됩니다. 아무도 간단한 몇 줄의 코드를 줄 수 있습니까 – Aryabhatta
Xidel, cmdline 도구를 사용하여 XML 문서를 파싱하려고합니다. http://www.videlibri.de/xidel.html – user2956477