读取文本文件中的值以在批处理文件变量中设置

时间:2014-04-19 09:06:27

标签: batch-file

@echo off
reg query HKEY_LOCAL_MACHINE\SOFTWARE\Candle\KNT\Ver610\Primary\Environment\ >nul
if %ERRORLEVEL% EQU 0 (
    echo "Key is added into 32 bit"
    cd /d "%CANDLE_HOME%\logs" & (for /f "tokens=1,2 delims=|" %%a in (Account_Detail.txt) do set "value1=%%a"&set "value2=%%b") & cmd /v:on /c "(echo Windows Registry Editor Version 5.00& echo [HKEY_LOCAL_MACHINE\SOFTWARE\Candle\KNT\Ver610\Primary\Environment]& echo "CT_CMSTEST"="IP.SPIPE:#!value1!;IP.SPIPE:#!value2!")>ntenv.reg" & reg import ntenv.reg
) else (
    echo "Key is added into 64 bit"
    cd /d "%CANDLE_HOME%\logs" & (for /f "tokens=1,* delims=|" %%a in (Account_Detail.txt) do set "value1=%%a"&set "value2=%%b") & cmd /v:on /c "(echo Windows Registry Editor Version 5.00& echo [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Candle\KNT\Ver610\Primary\Environment]& echo "CT_CMSTEST"="IP.SPIPE:#!value1!;IP.SPIPE:#!value2!")>ntenv.reg" & reg import ntenv.reg
    if EXIST %candle_home%\TMAITM6\kntcma.ini (
        echo CTIRA_SUBSYSTEM_ID=>>C:\IBM\ITM\TMAITM6\kntcma.ini
        cd /d "%CANDLE_HOME%\logs" & (for /f "tokens=3,* delims=|" %%a in (Account_Detail.txt) do set "value3=%%a") & cmd /v:on /C "(echo CTIRA_HOSTNAME=%value3%_%computername%     .TYPE=REG_EXPAND_SZ>>C:\IBM\ITM\TMAITM6\kntcma.ini) else (
        echo CTIRA_SUBSYSTEM_ID=>>C:\IBM\ITM\TMAITM6_x64\kntcma.ini
        cd /d "%CANDLE_HOME%\logs" & (for /f "tokens=3,* delims=|" %%a in (Account_Detail.txt) do set "value3=%%a") & cmd /v:on /C "(echo CTIRA_HOSTNAME=%value3%_%computername%     .TYPE=REG_EXPAND_SZ>>C:\IBM\ITM\TMAITM6_x64\kntcma.ini))

请在这里帮助我...我已经更改但无法执行...执行该命令是否有任何字符限制。这两个命令都在运行。

cd /d "%CANDLE_HOME%\logs" & (for /f "tokens=3,* delims=|" %%a in (Account_Detail.txt) do set "value3=%%a") & cmd /v:on /C "(echo CTIRA_HOSTNAME=%value3%_%computername%     .TYPE=REG_EXPAND_SZ>>C:\IBM\ITM\TMAITM6\kntcma.ini

请帮我解决这个问题。

2 个答案:

答案 0 :(得分:0)

命令行参数怎么样?

cd %CANDLE_HOME%\logs 
set "value1=%~1"
set "value2=%~2"
(echo Windows Registry Editor Version 5.00 
 echo [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Candle\KNT\Ver610\Primary\Environment] 
 echo "CT_CMSTEST"="IP.SPIPE:#%value1%;IP.SPIPE:#%value2%"
 )>ntenv.reg 
 reg import ntenv.reg

并将其称为my_bat.bat my_value1 my_value2

或者您只能使用set "value1=my_value"..

预设值

答案 1 :(得分:0)

file.txt放在同一个logs文件夹中,其中两个文字项由管道隔开:

192.168.1.1|192.168.1.2

然后这应该有效:

cd /d "%CANDLE_HOME%\logs" & (for /f "tokens=1,* delims=|" %%a in (file.txt) do set "value1=%%a"&set "value2=%%b") & cmd /v:on /c "(echo Windows Registry Editor Version 5.00& echo [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Candle\KNT\Ver610\Primary\Environment]& echo "CT_CMSTEST"="IP.SPIPE:#!value1!;IP.SPIPE:#!value2!")>ntenv.reg" & reg import ntenv.reg