@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はいくつかのオプションになります。バッチファイルがそれを行うためには、それを行うには無理な力を使います。 – Squashman
ほぼ完了です。バッチスクリプトのxmlファイルにhttpPort = "< >"の新しい値を入れたいだけです。誰も簡単な数行のコードを与えることができます – Aryabhatta
Xidel、cmdlineツールをXML文書の解析に使用してみてください。 http://www.videlibri.de/xidel.html – user2956477