Batch : ECHO outputs chinese character instead of numbers

  batch-file, character-encoding, cjk, cmd, windows

I’m trying to work around some logs to extract the data I want and to push it into another simplified .txt file (before going for the next step).

Here’s the bit of code I’ve been trying to use to reach my goal:

setlocal ENABLEDELAYEDEXPANSION 

for %%i in (C:Test_Analyse*files*.txt) do (
SET va=%%i
SET va=!va:~16,-31!
find /v /c "" %%i | FINDSTR /V /R /C:"^$">>C:test_results!va!log3.txt
set /p var=<C:test_results!va!log3.txt
set var=!var:~68,10!
echo !var!>>C:test_results!va!log2.txt
)

endlocal

The C:test_results!va!log3.txt file content is : ---------- C:TEST_ANALYSEK43782_TEST_RENAMED_FILES_20210915.TXT: 223856.

As far as I know, it does its job except for the echo !var!>>C:test_results!va!log2.txt part. It prints Chinese characters in my output file instead of 223856. On a side note, when I discard the @echo OFF, I notice the ECHO line working properly in CMD – so I guess it’s maybe about encryption? But I tried a few things around that, without success sadly.

Source: Windows Questions

LEAVE A COMMENT