我正在做像
这样的代码echo on
SET /P CONTROLSTRING_0326 = < sample.txt
rem sample.txt has data as 00000000000000000000000000000000000002017060000000000000000
ECHO %CONTROLSTRING_0326%
pause
SET CONTROL_DATE = %CONTROLSTRING_0326:~39,6%
ECHO %CONTROL_DATE%
PAUSE
SET filler1="2226 0000000 00000000000 00000000000
SET filler2= CONTROL 06.30"
PAUSE
SET "FINAL_CONTROL_2460 = %filler1%%CONTROL_DATE%%filler2%"
SET FINAL_CONTROL_2460
pause
SET FINAL_CONTROL_2460 > new_control.txt
PAUSE
EXIT
我希望文件new_control.txt应该包含以下数据
2226 0000000 00000000000 00000000000 201706 CONTROL 06.30"
但是我在new_control.txt中获取数据为“echo is on”。 不确定出了什么问题?
答案 0 :(得分:0)
问题是在SET命令中=
之前不应该有空格字符。你创建的是一个名为&#34; CONTROL_DATE&#34;的变量。而不是&#34; CONTROL_DATE&#34;。
更改
SET /P CONTROLSTRING_0326 = < sample.txt
SET CONTROL_DATE = %CONTROLSTRING_0326:~39,6%
SET "FINAL_CONTROL_2460 = %filler1%%CONTROL_DATE%%filler2%"
到
SET /P "CONTROLSTRING_0326=" < sample.txt
SET "CONTROL_DATE=%CONTROLSTRING_0326:~39,6%"
SET "FINAL_CONTROL_2460=%filler1%%CONTROL_DATE%%filler2%"