23

Accidentally found obscure Chinese poem (BAT file)

Something really weird just happened. I ran this in a batch file:

wmic timezone get caption>>tmp_ist.bak
time/date>>tmp_ist.bak

This was by accident, the time/date was a note to myself for %TIME%>>, anyway the batch file halted and I looked in the .bak file and:

Caption (UTC+09:30) Adelaide
桔⁥祳瑳浥挠湡潮⁴捡散瑰琠敨琠浩⁥湥整敲⹤਍湅整⁲桴⁥敮⁷楴敭›

...got weirder, this translates to:

Orange ⁥ 祳瑳絣 scratch the tide ⁴ pick up the scattered roses and scatter the treasure ⁥ 琠 Hao ⁥ ṥṣṣṣṣṇṣṣṇṣ�

It triggered the time command and tried to enter /date, when that's done (in prompt) it says:

The system cannot accept the time entered.

Not quite such beautiful wording. I have no clue what is going on here!!!

phuclv
  • 30,396
  • 15
  • 136
  • 260
LDAsh
  • 349

2 Answers2

25

The issue is due to the mixed use of wmic which always outputs UTF-16 text in the default output format

All WMIC output is UTF16 Unicode text with a BOM, convert this to plain ASCII with TYPE or MORE.
e.g. WMIC OS LIST BRIEF |more >> "C:\demo.txt"

https://ss64.com/nt/wmic.html

桔⁥祳瑳浥挠湡潮⁴捡散瑰琠敨琠浩⁥湥整敲⹤਍湅整⁲桴⁥敮⁷楴敭› is U+6854 U+2065 U+7973 U+7473 U+6D65 U+6320 U+6E61 U+6F6E U+2074 U+6361 U+6563 U+7470 U+7420 U+6568 U+7420 U+6D69 U+2065 U+6E65 U+6574 U+6572 U+2E64 U+0A0D U+6E45 U+6574 U+2072 U+6874 U+2065 U+656E U+2077 U+6974 U+656D U+203A which results in the following byte sequence when encoded in UTF-16 (LE)

54 68 65 20 73 79 73 74 65 6D 20 63 61 6E 6E 6F 74 20 61 63 63 65 70 74 20 74 68 65 20 74 69 6D 65 20 65 6E 74 65 72 65 64 2E 0D 0A 45 6E 74 65 72 20 74 68 65 20 6E 65 77 20 74 69 6D 65 3A 20

and when treating the same byte sequence as ASCII it becomes

The system cannot accept the time entered.
Enter the new time:

Here I'm using PowerShell to demonstrate it easier. The output of time command is as expected:

PS D:\> cmd /c "time/date > time.txt" ^C
PS D:\> Format-Hex .\time.txt
       Path: D:\time.txt

       00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F

00000000 54 68 65 20 73 79 73 74 65 6D 20 63 61 6E 6E 6F The system canno 00000010 74 20 61 63 63 65 70 74 20 74 68 65 20 74 69 6D t accept the tim 00000020 65 20 65 6E 74 65 72 65 64 2E 0D 0A 45 6E 74 65 e entered...Ente 00000030 72 20 74 68 65 20 6E 65 77 20 74 69 6D 65 3A 20 r the new time:

However the output of wmic is always UTF-16, that's why there's the FF FE BOM signature at the start. And when you append the time output to that file it becomes completely garbage due to the wrong encoding

PS D:\> cmd /c "wmic timezone get caption > wmic.txt"
PS D:\> Format-Hex wmic.txt
       Path: D:\wmic.txt

       00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F

00000000 FF FE 43 00 61 00 70 00 74 00 69 00 6F 00 6E 00 .þC.a.p.t.i.o.n. 00000010 20 00 20 00 20 00 20 00 20 00 20 00 20 00 20 00 . . . . . . . . 00000020 20 00 20 00 20 00 20 00 20 00 20 00 20 00 20 00 . . . . . . . . 00000030 20 00 20 00 20 00 20 00 20 00 20 00 20 00 20 00 . . . . . . . . 00000040 20 00 20 00 20 00 20 00 20 00 20 00 0D 00 0A 00 . . . . . ..... 00000050 28 00 55 00 54 00 43 00 2B 00 30 00 37 00 3A 00 (.U.T.C.+.0.7.:. 00000060 30 00 30 00 29 00 20 00 42 00 61 00 6E 00 67 00 0.0.). .B.a.n.g. 00000070 6B 00 6F 00 6B 00 2C 00 20 00 48 00 61 00 6E 00 k.o.k.,. .H.a.n. 00000080 6F 00 69 00 2C 00 20 00 4A 00 61 00 6B 00 61 00 o.i.,. .J.a.k.a. 00000090 72 00 74 00 61 00 20 00 20 00 0D 00 0A 00 r.t.a. . .....

PS D:> cmd /c "time/date >> wmic.txt" ^C PS D:> Format-Hex wmic.txt

       Path: D:\wmic.txt

       00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F

00000000 FF FE 43 00 61 00 70 00 74 00 69 00 6F 00 6E 00 .þC.a.p.t.i.o.n. 00000010 20 00 20 00 20 00 20 00 20 00 20 00 20 00 20 00 . . . . . . . . 00000020 20 00 20 00 20 00 20 00 20 00 20 00 20 00 20 00 . . . . . . . . 00000030 20 00 20 00 20 00 20 00 20 00 20 00 20 00 20 00 . . . . . . . . 00000040 20 00 20 00 20 00 20 00 20 00 20 00 0D 00 0A 00 . . . . . ..... 00000050 28 00 55 00 54 00 43 00 2B 00 30 00 37 00 3A 00 (.U.T.C.+.0.7.:. 00000060 30 00 30 00 29 00 20 00 42 00 61 00 6E 00 67 00 0.0.). .B.a.n.g. 00000070 6B 00 6F 00 6B 00 2C 00 20 00 48 00 61 00 6E 00 k.o.k.,. .H.a.n. 00000080 6F 00 69 00 2C 00 20 00 4A 00 61 00 6B 00 61 00 o.i.,. .J.a.k.a. 00000090 72 00 74 00 61 00 20 00 20 00 0D 00 0A 00 54 68 r.t.a. . .....Th 000000A0 65 20 73 79 73 74 65 6D 20 63 61 6E 6E 6F 74 20 e system cannot 000000B0 61 63 63 65 70 74 20 74 68 65 20 74 69 6D 65 20 accept the time 000000C0 65 6E 74 65 72 65 64 2E 0D 0A 45 6E 74 65 72 20 entered...Enter 000000D0 74 68 65 20 6E 65 77 20 74 69 6D 65 3A 20 the new time:

The ANSI output is treated as UTF-16, resulting in the result similar to the Bush hid the facts bug. In the question you only show the >> but probably its initial output was from wmic

You can use some tricks, like piping to more as mentioned above to convert wmic output to ANSI

wmic timezone get caption | more >> tmp_ist.bak

Anyway wmic was deprecated long ago, the new PowerShell cmdlets should be used instead

phuclv
  • 30,396
  • 15
  • 136
  • 260
5

"The issue is due to the use of wmic which always outputs UTF-16 text"

This is not really true, because wmic can give output in different encodings depending on the /format you choose.

It's not just about using wmic, but what you put after /format:[here].

Different format options will lead to different output encodings, which can affect how you handle the result. The way the output comes can make string handling easier or harder, depending on where you're sending it or how you want to use it.

Simpler formats are usually easier to read and parse in scripts, while more structured ones might be better for programmatic use, even if they require dealing with things like UTF-16. Again, it all depends on the scenario and the actions you take with the output.


  • See for yourself:
@echo off

>."tmp_ist.bak" cd /d "%~dp0"

for /f usebackq^tokens^=4delims^=^<^> %%i in =;(wmic timezone get caption /format:xml ^| find &quot;VALUE&quot;);= do >.&quot;tmp_ist.bak" =;( echo/%%~i for %%G in =;(time,date);= do call echo/%%%%~G%% );=

timeout -1 | type .&quot;tmp_ist.bak"


  • Here content of the file .\"tmp_ist.bak" is:
(UTC-03:00) Brasilia
22:51:05.46
Sat 04/19/20

  • You can also get the same output using:
@echo off

>.&quot;tmp_ist.bak" cd /d "%~dp0"

for /f useback^tokens^=3* %%i in =;(systeminfo ^| findstr /C:&quot;Time Zone&quot;);= do >.&quot;tmp_ist.bak" =;( echo/%%~i %%~j for %%G in =;(time,date);= do call echo/%%%%~G%% );=

timeout -1 | type .&quot;tmp_ist.bak"


  • Output:
(UTC-03:00) Brasilia
23:12:46.99
Sat 04/19/2025
Io-oI
  • 9,237