You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何编写Windows .bat文件实现HTTPPortNumber端口号自增

Batch Script to Increment HTTPPortNumber in TM1 Config File

Solution Overview

We’ll combine Batch and PowerShell commands in a single .bat file to handle reading the config, modifying the port value, and saving changes back—avoiding the variable storage issue you encountered earlier.

Complete Batch Script

@echo off
setlocal enabledelayedexpansion

:: Define your config file path
set "CONFIG_FILE=C:\Work\Clients\bcg\Config\Tm1s.cfg"

:: PowerShell command to modify the port number
powershell -Command "$content = Get-Content '%CONFIG_FILE%'; $newContent = $content | ForEach-Object { if ($_ -match '^HTTPPortNumber=(\d+)$') { 'HTTPPortNumber=' + ([int]$matches[1] + 1) } else { $_ } }; $newContent | Set-Content '%CONFIG_FILE%'"

echo HTTPPortNumber incremented successfully.
endlocal

Key Step Breakdown

  • Read the config: Get-Content '%CONFIG_FILE%' loads the entire file into a variable.
  • Target the port line: The regex ^HTTPPortNumber=(\d+)$ matches only lines exactly formatted as HTTPPortNumber=####, capturing the numeric port value.
  • Increment and rewrite: When a match is found, the captured port is converted to an integer, incremented by 1, and the line is reconstructed. All other lines remain unchanged.
  • Save changes: Set-Content '%CONFIG_FILE%' writes the modified content back to the original file.

Testing Tips

  • Verify you have write permissions for the config file path.
  • Test with a copy of the IBM sample cfg file first to prevent accidental data loss.

内容的提问来源于stack exchange,提问作者Red Arlint

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 11:11:08