I'm 99% done with my batchfile and now I'm facing the very last obstactle which just doesn't seem to want to go away. This is the current script:
@echo off
SET SPT4="C:\Testfolder\Test.Screen.txt"
SET SPT6="C:\Testfolder\Test.Screen.Temp.txt"
Type %SPT4% | Findstr "SerialNumberID= UserFriendlyName=" > C:\Testfolder\Temp.txt
Echo Screenmodel: > %SPT6%
for /f "delims=" %%x in (C:\Testfolder\Temp.txt) DO (
echo %%x
::Processing the gained informations.
set SN1=%%x
echo %SN1%
set "list=%SN1: =%"
echo %list%
set "list=%x:{= %"
set "list=%list:}= %"
set "list=%list:SerialNumberID= %"
set "list=%list:UserFriendlyName= %"
Echo %list%
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
(
FOR %%y IN (%list%) DO (
cmd /c exit %%y
<nul set /p =!=exitcodeAscii!
) >> %SPT6%
)
Echo. >> %SPT6%
)
del C:\Testfolder\Temp.txt
timeout 10 /nobreak > nul
The script first defines the variables and filters out a file with the screeninformations provided in another file so I end up with only 4 lines which are saved in the Temp.txt.
Here are the informations from the file "Temp.txt"
SerialNumberID={89,86,51,84,49,55,52,49,52,49,0,0,0,0,0,0}
UserFriendlyName={66,49,57,45,54,32,76,69,68,0,0,0,0}
SerialNumberID={53,90,48,57,54,55,51,52,78,66,0,0,0,0,0,0}
UserFriendlyName={69,65,50,52,52,87,77,105,0,0,0,0,0}
The script itself works fine but I need to remove all the unnecessary characters like "= { }". So in order to do so I want to pass the informations to the var %list%
but when I want to echo it I only recieve a message like
Echo disabled / Echo Command deactivated
The final output also is not a clear name but a blank line.
When I replace the %list with %%x the whole thing works as intended but the first letter is missing from all the lines due to the "= { }"
Can someone please give me an idea on what to try to solve this issue? I know it's something really small I'm probably missing.
Solution:
I had to replace the middle part of the code with this:
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
(
for /f "delims=" %%x in (C:\Testfolder\Temp.txt) DO (
::Processing the gained informations.
set SN1=%%x
echo !SN1!
set "list=!SN1!"
echo 1 !list!
set "list=!list:}= !"
echo 2 !list!
set "list=!list:{= !"
echo 3 !list!
set "list=!list:SerialNumberID= !"
echo 4 !list!
set "list=!list:UserFriendlyName= !"
echo 5 !list!
echo.
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
(
FOR %%y IN (!list!) DO (
cmd /c exit %%y
<nul set /p =!=exitcodeAscii!
) >> %SPT6%
)
Echo. >> %SPT6%
)
)
So the actual problem was I tried to use variables like %var% instead of !var!