<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>技术 on LEl_FENG Blog</title><link>https://blog.xpdbk.com/en/categories/%E6%8A%80%E6%9C%AF/</link><description>Recent content in 技术 on LEl_FENG Blog</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>LEl_FENG Copyright</copyright><lastBuildDate>Tue, 12 Sep 2023 21:13:11 +0700</lastBuildDate><atom:link href="https://blog.xpdbk.com/en/categories/%E6%8A%80%E6%9C%AF/index.xml" rel="self" type="application/rss+xml"/><item><title>Batchfile batch script garbled solution</title><link>https://blog.xpdbk.com/en/posts/batchfile-fix-lange-erorr/</link><pubDate>Tue, 12 Sep 2023 21:13:11 +0700</pubDate><guid>https://blog.xpdbk.com/en/posts/batchfile-fix-lange-erorr/</guid><description>&lt;blockquote>
&lt;p>&lt;strong>TL;DR / [Geek Summary]:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Encoding mismatch is the root of all evil; it&amp;rsquo;s a battle between ANSI and UTF-8.&lt;/li>
&lt;li>Brute Force: Simply Save As ANSI using Notepad—quick, dirty, and effective.&lt;/li>
&lt;li>Elegant Upgrade: Inject the &lt;code>chcp 65001&lt;/code> command at the script&amp;rsquo;s header to force the code page to UTF-8.&lt;/li>
&lt;/ul>
&lt;/blockquote>
&lt;h2 id="question">
&lt;a href="#question" class="heading-anchor" aria-label="Anchor for question">#&lt;/a>
question
&lt;/h2>
&lt;p>The bat batch processing script is as follows&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">@echo off
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">echo hello,world.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">echo haha
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">pause
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>When CMD executes the script, Chinese garbled characters appear.&lt;/p>
&lt;h2 id="analyze">
&lt;a href="#analyze" class="heading-anchor" aria-label="Anchor for analyze">#&lt;/a>
analyze
&lt;/h2>
&lt;ol>
&lt;li>
&lt;p>Garbled characters are all related to character encoding. .&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Computers can only process numbers. If text is encountered, it must be converted to a number before processing. This is where character encodings (character sets) come in. . If you use a certain character encoding for encoding, you must use the same character encoding for decoding. If different character encodings are used, garbled characters will appear. .&lt;/p>
&lt;/li>
&lt;/ol>
&lt;h2 id="solve">
&lt;a href="#solve" class="heading-anchor" aria-label="Anchor for solve">#&lt;/a>
solve
&lt;/h2>
&lt;h3 id="convert-the-encoding-of-script-files">
&lt;a href="#convert-the-encoding-of-script-files" class="heading-anchor" aria-label="Anchor for Convert the encoding of script files">#&lt;/a>
Convert the encoding of script files
&lt;/h3>
&lt;p>By default, in the bat script file, if the Chinese is not ANSI encoding, garbled characters will appear. Therefore, you can use the Notepad that comes with the Windows operating system platform to open the script file, click the menu [File] - [Save As], and select ANSI encoding to save.&lt;/p>
&lt;p>After converting the encoding and running it again, the Chinese garbled problem was solved.&lt;/p>
&lt;h3 id="change-code">
&lt;a href="#change-code" class="heading-anchor" aria-label="Anchor for Change code">#&lt;/a>
Change code
&lt;/h3>
&lt;p>Declare changes to the previous code in the original bat script file&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">chcp 65001
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h2 id="other">
&lt;a href="#other" class="heading-anchor" aria-label="Anchor for other">#&lt;/a>
other
&lt;/h2>
&lt;ol>
&lt;li>Common code page mapping&lt;/li>
&lt;/ol>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>code page&lt;/th>
&lt;th>mapped character set&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>936&lt;/td>
&lt;td>GB2312&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>20127&lt;/td>
&lt;td>US-ASCII&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>65001&lt;/td>
&lt;td>UTF-8&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table></description></item></channel></rss>