Output file garbled when reading batch file

Asked 2 years ago, Updated 2 years ago, 117 views

I'm creating a batch file that writes SJIS to an xml file.

When I import into SJIS and check the XML file, I get garbled or missing Japanese characters error.

Example
SJIS (Example AAA.TXT)

1. Panda
2, sheep
・・・

XML (AAAXML)

<?xml version="1.0" encoding="UTF-8"?> 
<Code Code="1" content=" 

will be

Even though the file probably contains utf-8
Since I use SJIS, I think the characters will disappear if I look at IE etc.
Is it possible to convert SJIS to UTF-8 and save it when SJIS saves it?
Thank you for your cooperation.

A simple uptake statement is
for /f%%ain(AAA.TXT)do(ECHO%a>AAA.XML).

batch-file

2022-09-30 19:22

1 Answers

In a batch file execution environment (CMD.EXE and its associated Windows standard commands), it is unlikely that you can specify a separate input file character code, work variable, and output file character code in a single line of commands/scripts, and make it UTF-8.

It would be a good idea to deal with one of the following or a variety of them:

  • All processing until XML file is done by shift JIS and then converted to UTF-8 with nkf, iconv, or some other script or command
  • Create processing with scripting tools and commands such as PowerShell and Python that allow you to specify input/output character codes separately.


2022-09-30 19:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.