简体   繁体   中英

Changed System Locale? Batch script now gets incorrect text

So I've been working on a batch script to extract certain strings from a txt document, and it was extracting FINE until I changed my system Locale to japan (at least I think thats what caused it, Either System Locale = japan or robocopy failing to copy the file correctly). Now Its outputting incorrect text, and im not sure why.

What The script previously grabbed
textE("海沿いに立つ高級フィットネスリゾート施設。");

What it Grabs now
textE("豬キ豐ソ縺・↓遶九▽鬮倡エ壹ヵ繧」繝・ヨ繝阪せ繝ェ繧セ繝シ繝域命險ュ縲・);

The Only thing that changed was My Systems Locale Setting as far as I know, And I am using Robocopy to copy the files containing the text.
This is the Script Im using to grab text out of text files.
@echo off set /a tcount=0 for /r %%Z in (*.as) do ( SET /a lcount=0 for /F "eol=; tokens=1,2* usebackq delims=(" %%A in ("%%Z") do ( set /a lcount+=1 if /i %%A==texte set /a tcount+=1 & echo LN,!lcount!,%%A(%%B ) echo LC,!lcount! SET /a lcount=0 set /a fcount+=1 ) > "%%Z.txt"
Just ignore the counters they keep track of some generic data I Write to the bottom of the text file. (Number of strings, Total Number of lines, Line string is on, etc)

Anyway, I don't know how to fix the Unicode issue, because its Clearly no longer reading the files correctly. Basically If I create a .as file that contains any Japanese text Like the first line up top, its getting read incorrectly and giving me weird symbols and stuff in the output file.

The Only Other thing I changed that Might have caused it is I started using Robocopy, And Im not sure If it might be breaking the text when it copies.

@echo off robocopy "%~dp0\\" "%temp%\\temporarybatchfolder" *.txt /s /mov /XD InProgress robocopy "%temp%\\temporarybatchfolder" "%~DP0\\InProgress" *.txt /s /mov
I don't know much about robocopy, I remember seeing something related to unicode and robocopy but I'm not sure where I saw it.

PS: Minor Unrelated question, but how can I get the extraction bit to output to the screen and still save the lines into %%Z.txt (EG I want to be able to echo Current file and other data without it getting written to the text file, so user/me can see How the progress is (It takes around 2-3 minutes to process all the files, and so it looks like the batch file hangs).

EDIT: So, I did a couple Tests Just to see whats going on, It would seem that the for /f loop is causing the issue.
EG The First line in the .as file is
// Action script...
But The For loops is returning
・ソ// Action script...
Now I have no idea where the ・ ソ came from but i believe it has to do with the files encoding format being utf8, At least that's what notepad++ Is saying its in.
I checked the .txt file that is created, and its encoding format is UTF-8 Without BOM. So I'm guessing this has something to do with the problem? Honestly Im pretty Lost as to what the problem is, since it was working fine before I restarted my system and changed the system Locale

I managed to fix the issue simply using
chcp 65001
The Reason I was getting "The System Cannot Write To Specified Device" error was due to the fact that my Command Window's Font doesn't support unicode (At Least I think that's what was causing it, Since its writing fine to the text files).

Anyway Hopefully Someone Might Find This useful.

CHCP Help (Contains a few of the Commonly Used Locale Codes along with Usage information).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM