any time i use batch to edit a signal line of text (really it just one character that changes) the file gets a little bigger. it shouldn't do that if the amount of text is the same again one character.
任何时候我使用批处理编辑信号行的文本(实际上它只是一个字符更改)文件变得更大。如果文本的数量再次与一个字符相同,则不应该这样做。
what I'm trying to do is launch a program (an emulator called blueMSX) and have it so the bat changes a setting according to what I put in. since the devs I guess didn't feel it necessary to put in robust command line capabilities beyond the basics i have to do it by changing a line in the config ini.
我正在尝试做的是启动一个程序(一个名为blueMSX的模拟器)并让它根据我输入的内容更改设置。因为开发人员我认为没有必要放入健壮的命令行我必须通过更改config ini中的一行来实现基本功能之外的功能。
While it does work somehow extra data is being tacked on. Not only does this mean the file will get bigger and bigger every time its used by the bat but worse still the emulator i guess dosn't like it either and just adds in completely new settings after the old. and before anyone ask no the extra data is not the new settings as I have tested this without starting the program at all and just changing the text. here is the code in question
虽然它确实有效,但正在加强额外的数据。这不仅意味着文件每次被蝙蝠使用时都会变得越来越大,但更糟糕的是模拟器,我猜也不喜欢它,只是在旧的后面添加了全新的设置。并且在没有人问任何额外的数据不是新的设置,因为我已经测试了这个,而根本没有启动程序,只是更改文本。这是有问题的代码
@echo off
:again
set alright=n
echo Enter 5 for 50hz or 6 for 60hz
set /p strUserInput=50hz or 60hz:
if %strUserInput%==5 (
set alright=y
)
if %strUserInput%==6 (
set alright=y
)
if %alright%==n goto again
setlocal EnableDelayedExpansion
break > "%CD%\blueMSXv282full\bluemsxTemp.ini"
set strLineToChange=emulation.vdpSyncMode^=
for /f "usebackq tokens=* delims=~" %%a in ("%CD%\blueMSXv282full\bluemsx.ini") do (
set strLine=%%a
IF "!strLine:~0,22!"=="%strLineToChange%" (
echo %strLineToChange%%strUserInput%0Hz >> "%CD%\blueMSXv282full\bluemsxTemp.ini"
) ELSE (
echo %%a >> "%CD%\blueMSXv282full\bluemsxTemp.ini"
)
)
del "%CD%\blueMSXv282full\bluemsx.ini"
rename "%CD%\blueMSXv282full\bluemsxTemp.ini" "bluemsx.ini"
start /D "%CD%\blueMSXv282full\" "blueMSX.exe" "%CD%\blueMSXv282full\blueMSX.exe" -rom1 "%~1"
one more thing if i make the edit manually with notepad it works fine
还有一件事,如果我用记事本手动编辑,它工作正常
1 个解决方案
#1
1
echo %strLineToChange%%strUserInput%0Hz >> "%CD%\blueMSXv282full\bluemsxTemp.ini"
) ELSE (
echo %%a >> "%CD%\blueMSXv282full\bluemsxTemp.ini"
The spaces before the >>
will be output to the file, try
>>之前的空格将输出到文件,尝试
echo %strLineToChange%%strUserInput%0Hz>> "%CD%\blueMSXv282full\bluemsxTemp.ini"
) ELSE (
echo %%a>> "%CD%\blueMSXv282full\bluemsxTemp.ini"
#1
1
echo %strLineToChange%%strUserInput%0Hz >> "%CD%\blueMSXv282full\bluemsxTemp.ini"
) ELSE (
echo %%a >> "%CD%\blueMSXv282full\bluemsxTemp.ini"
The spaces before the >>
will be output to the file, try
>>之前的空格将输出到文件,尝试
echo %strLineToChange%%strUserInput%0Hz>> "%CD%\blueMSXv282full\bluemsxTemp.ini"
) ELSE (
echo %%a>> "%CD%\blueMSXv282full\bluemsxTemp.ini"