chcp.com clearing the terminal screen after executing it #12959

Open
opened 2026-01-31 03:30:01 +00:00 by claunia · 20 comments
Owner

Originally created by @patrick330602 on GitHub (Mar 11, 2021).

Environment

Windows build number: 21332
Windows Terminal version (if applicable): N/A

Any other software?

Steps to reproduce

  1. execute chcp.com <different code page> in PowerShell/cmd/WSL from old conhost.exe or Windows Terminal

Expected behavior

It should print out the current code page without clearing the terminal

Actual behavior

It will clear the terminal screen and then print out the current code page.

Other

I also reported the bug in Feedback Hub in case this is not the proper place to report it: https://aka.ms/AAbh6ni

Originally created by @patrick330602 on GitHub (Mar 11, 2021). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> <!-- This bug tracker is monitored by Windows Terminal development team and other technical folks. **Important: When reporting BSODs or security issues, DO NOT attach memory dumps, logs, or traces to Github issues**. Instead, send dumps/traces to secure@microsoft.com, referencing this GitHub issue. If this is an application crash, please also provide a Feedback Hub submission link so we can find your diagnostic data on the backend. Use the category "Apps > Windows Terminal (Preview)" and choose "Share My Feedback" after submission to get the link. Please use this form and describe your issue, concisely but precisely, with as much detail as possible. --> # Environment ```none Windows build number: 21332 Windows Terminal version (if applicable): N/A Any other software? ``` # Steps to reproduce 1. execute `chcp.com <different code page>` in PowerShell/cmd/WSL from old `conhost.exe` or Windows Terminal <!-- A description of how to trigger this bug. --> # Expected behavior It should print out the current code page without clearing the terminal <!-- A description of what you're expecting, possibly containing screenshots or reference material. --> # Actual behavior It will clear the terminal screen and then print out the current code page. <!-- What's actually happening? --> # Other I also reported the bug in Feedback Hub in case this is not the proper place to report it: https://aka.ms/AAbh6ni
claunia added the Issue-BugArea-ServerProduct-Conpty labels 2026-01-31 03:30:02 +00:00
Author
Owner

@zadjii-msft commented on GitHub (Mar 11, 2021):

That's definitely unexpected - which code page are you coming from and changing to?

@zadjii-msft commented on GitHub (Mar 11, 2021): That's definitely unexpected - which code page are you coming from and changing to?
Author
Owner

@patrick330602 commented on GitHub (Mar 11, 2021):

That's definitely unexpected - which code page are you coming from and changing to?

This issue in my case exists when switching from/to the code page 932, and from my test, the issue does not exist for codepage 437

@patrick330602 commented on GitHub (Mar 11, 2021): > That's definitely unexpected - which code page are you coming from and changing to? This issue in my case exists when switching from/to the code page 932, and from my test, the issue does not exist for codepage 437
Author
Owner

@DHowett commented on GitHub (Mar 11, 2021):

Can you run gcm chcp -all from powershell?

@DHowett commented on GitHub (Mar 11, 2021): Can you run `gcm chcp -all` from powershell?
Author
Owner

@patrick330602 commented on GitHub (Mar 12, 2021):

image

@patrick330602 commented on GitHub (Mar 12, 2021): ![image](https://user-images.githubusercontent.com/15316889/110882865-885cb780-831d-11eb-91a2-c11020dc75e8.png)
Author
Owner

@jdebp commented on GitHub (Mar 13, 2021):

Two points:

  • Does it matter what is on screen at the time? Is it mainly kana/kanji? Or English characters? A mixture of both?
  • What is in the output file when you redirect the output of chcp 932 to file? What does Format-Hex on that file tell you?
@jdebp commented on GitHub (Mar 13, 2021): Two points: * Does it matter what is on screen at the time? Is it mainly kana/kanji? Or English characters? A mixture of both? * What is in the output file when you redirect the output of `chcp 932` to file? What does `Format-Hex` on that file tell you?
Author
Owner

@eryksun commented on GitHub (Mar 13, 2021):

Try alternate ways to set the console I/O code pages:

mode.com con cp select=932

PowerShell:

[console]::OutputEncoding = [System.Text.Encoding]::GetEncoding(932)
[console]::InputEncoding = [System.Text.Encoding]::GetEncoding(932)

PSReadLine in PowerShell 7.1 has odd behavior in this case. It enables the configured output code page only when enter is pressed to run an internal or external command. When control is returned to PSReadLine, it resets the output code page to UTF-8 (65001). This causes the screen to be re-displayed for every line of input, even if just for a brief flash when enter is pressed for an empty line. Revert to normal behavior by unloading it: Remove-Module PSReadLine.

Python:

py -c "import ctypes; ctypes.WinDLL('kernel32').SetConsoleOutputCP(932)"
py -c "import ctypes; ctypes.WinDLL('kernel32').SetConsoleCP(932)"
@eryksun commented on GitHub (Mar 13, 2021): Try alternate ways to set the console I/O code pages: mode.com con cp select=932 PowerShell: [console]::OutputEncoding = [System.Text.Encoding]::GetEncoding(932) [console]::InputEncoding = [System.Text.Encoding]::GetEncoding(932) PSReadLine in PowerShell 7.1 has odd behavior in this case. It enables the configured output code page only when enter is pressed to run an internal or external command. When control is returned to PSReadLine, it resets the output code page to UTF-8 (65001). This causes the screen to be re-displayed for every line of input, even if just for a brief flash when enter is pressed for an empty line. Revert to normal behavior by unloading it: `Remove-Module PSReadLine`. Python: py -c "import ctypes; ctypes.WinDLL('kernel32').SetConsoleOutputCP(932)" py -c "import ctypes; ctypes.WinDLL('kernel32').SetConsoleCP(932)"
Author
Owner

@patrick330602 commented on GitHub (Mar 14, 2021):

Two points:

  • Does it matter what is on screen at the time? Is it mainly kana/kanji? Or English characters? A mixture of both?

It's just only English

  • What is in the output file when you redirect the output of chcp 932 to file? What does Format-Hex on that file tell you?

It just says "Active code page: 932".

The Format-Hex result is:



           Path: C:\Users\patrick\a

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

00000000   FF FE 41 00 63 00 74 00 69 00 76 00 65 00 20 00  .þA.c.t.i.v.e. .
00000010   63 00 6F 00 64 00 65 00 20 00 70 00 61 00 67 00  c.o.d.e. .p.a.g.
00000020   65 00 3A 00 20 00 39 00 33 00 32 00 0D 00 0A 00  e.:. .9.3.2.....


@patrick330602 commented on GitHub (Mar 14, 2021): > Two points: > > * Does it matter what is on screen at the time? Is it mainly kana/kanji? Or English characters? A mixture of both? It's just only English > * What is in the output file when you redirect the output of `chcp 932` to file? What does `Format-Hex` on that file tell you? It just says "Active code page: 932". The `Format-Hex` result is: ``` Path: C:\Users\patrick\a 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 00000000 FF FE 41 00 63 00 74 00 69 00 76 00 65 00 20 00 .þA.c.t.i.v.e. . 00000010 63 00 6F 00 64 00 65 00 20 00 70 00 61 00 67 00 c.o.d.e. .p.a.g. 00000020 65 00 3A 00 20 00 39 00 33 00 32 00 0D 00 0A 00 e.:. .9.3.2..... ```
Author
Owner

@patrick330602 commented on GitHub (Mar 14, 2021):

Try alternate ways to set the console I/O code pages:

mode.com con cp select=932

This one has a similar behavior of clearing the terminal screen.

Also since I try to use it as a workaround for a PowerShell issue on WSL, the PowerShell method and Python method are not suitable for me...

@patrick330602 commented on GitHub (Mar 14, 2021): > Try alternate ways to set the console I/O code pages: > > ``` > mode.com con cp select=932 > ``` This one has a similar behavior of clearing the terminal screen. Also since I try to use it as a workaround for a PowerShell issue on WSL, the PowerShell method and Python method are not suitable for me...
Author
Owner

@eryksun commented on GitHub (Mar 14, 2021):

Also since I try to use it as a workaround for a PowerShell issue on WSL

Are you running CMD or PowerShell from WSL, and do you only experience the bug in that case? WSL executes a Windows console application such as cmd.exe in a conpty session, which may be an important detail, if you don't experience the same problem when running chcp.com from a regular console session.

It's also important to discover whether something other than SetConsoleOutputCP(932) in "chcp.com" or "mode.com" is clearing the screen, since both are based on ulib.dll for their user interface. Can you build a small program in C that just calls SetConsoleOutputCP(932)?

@eryksun commented on GitHub (Mar 14, 2021): > Also since I try to use it as a workaround for a PowerShell issue on WSL Are you running CMD or PowerShell from WSL, and do you only experience the bug in that case? WSL executes a Windows console application such as cmd.exe in a conpty session, which may be an important detail, if you don't experience the same problem when running chcp.com from a regular console session. It's also important to discover whether something other than `SetConsoleOutputCP(932)` in "chcp.com" or "mode.com" is clearing the screen, since both are based on ulib.dll for their user interface. Can you build a small program in C that just calls `SetConsoleOutputCP(932)`?
Author
Owner

@patrick330602 commented on GitHub (Mar 15, 2021):

Also since I try to use it as a workaround for a PowerShell issue on WSL

Are you running CMD or PowerShell from WSL, and do you only experience the bug in that case? WSL executes a Windows console application such as cmd.exe in a conpty session, which may be an important detail, if you don't experience the same problem when running chcp.com from a regular console session.

Executing chcp.com <different code page> in PowerShell/cmd/WSL directly from old conhost.exe or Windows Terminal all result in the terminal clear behavior.

It's also important to discover whether something other than SetConsoleOutputCP(932) in "chcp.com" or "mode.com" is clearing the screen, since both are based on ulib.dll for their user interface. Can you build a small program in C that just calls SetConsoleOutputCP(932)?

Thanks for the suggestion. I will try and look whether it solves the issue.

@patrick330602 commented on GitHub (Mar 15, 2021): > > Also since I try to use it as a workaround for a PowerShell issue on WSL > > Are you running CMD or PowerShell from WSL, and do you only experience the bug in that case? WSL executes a Windows console application such as cmd.exe in a conpty session, which may be an important detail, if you don't experience the same problem when running chcp.com from a regular console session. Executing `chcp.com <different code page>` in PowerShell/cmd/WSL directly from old conhost.exe or Windows Terminal all result in the terminal clear behavior. > > It's also important to discover whether something other than `SetConsoleOutputCP(932)` in "chcp.com" or "mode.com" is clearing the screen, since both are based on ulib.dll for their user interface. Can you build a small program in C that just calls `SetConsoleOutputCP(932)`? Thanks for the suggestion. I will try and look whether it solves the issue.
Author
Owner

@ghost commented on GitHub (Mar 19, 2021):

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

@ghost commented on GitHub (Mar 19, 2021): This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for **4 days**. It will be closed if no further activity occurs **within 3 days of this comment**.
Author
Owner

@jdebp commented on GitHub (Mar 21, 2021):

Part of the problem here is reproducing it. This does not happen as described for me, and I suspect that the Microsoft people are in the same boat. It has happened for this person for example, but there's not enough information there for people who do not experience this to reproduce it.

@jdebp commented on GitHub (Mar 21, 2021): Part of the problem here is reproducing it. This does not happen as described for me, and I suspect that the Microsoft people are in the same boat. It has happened for [this person](https://www.dostips.com/forum/viewtopic.php?t=8828) for example, but there's not enough information there for people who do not experience this to reproduce it.
Author
Owner

@patrick330602 commented on GitHub (Mar 22, 2021):

Hmm, then here is the complete language setup:
Country/Region: Hong Kong
Regional Format: English (Hong Kong SAR)
Windows Display: English (Hong Kong SAR)
Apps and Websites: English (Hong Kong SAR)
Keyboard: English (Hong Kong SAR) - US
Current language for non-Unicode programs: Japanese (Japan), Beta UTF-8 support not enabled

@patrick330602 commented on GitHub (Mar 22, 2021): Hmm, then here is the complete language setup: Country/Region: Hong Kong Regional Format: English (Hong Kong SAR) Windows Display: English (Hong Kong SAR) Apps and Websites: English (Hong Kong SAR) Keyboard: English (Hong Kong SAR) - US Current language for non-Unicode programs: Japanese (Japan), Beta UTF-8 support not enabled
Author
Owner

@DHowett commented on GitHub (Apr 14, 2021):

Okay, here's one more weird question. If you just run mode.com, what do you see?

@DHowett commented on GitHub (Apr 14, 2021): Okay, here's one more weird question. If you just run `mode.com`, what do you see?
Author
Owner

@patrick330602 commented on GitHub (Apr 16, 2021):

@DHowett

This is the result:

Status for device CON:
----------------------
    Lines:          30
    Columns:        120
    Keyboard rate:  31
    Keyboard delay: 1
    Code page:      932
@patrick330602 commented on GitHub (Apr 16, 2021): @DHowett This is the result: ``` Status for device CON: ---------------------- Lines: 30 Columns: 120 Keyboard rate: 31 Keyboard delay: 1 Code page: 932 ```
Author
Owner

@zadjii-msft commented on GitHub (Oct 26, 2022):

We've got this crazy thought that this might be related to the font for some reason.

  • Could you share your settings.json file?
  • Can you also export the contents of HKCU\Console, change the extension to .txt and paste it here/?
    image

I'm wondering if the reason we're not seeing this is there's some change in font that's occurring, which is triggering a clear?

Also quick confirm if you're still seeing this on whatever your latest Windows build and Terminal version? Sorry it's been so long 😬

@zadjii-msft commented on GitHub (Oct 26, 2022): We've got this crazy thought that this might be related to the font for some reason. * Could you share your [settings.json file](https://github.com/microsoft/terminal/wiki/Frequently-Asked-Questions-(FAQ)#where-can-i-find-the-settings-file)? * Can you also export the contents of `HKCU\Console`, change the extension to .txt and paste it here/? ![image](https://user-images.githubusercontent.com/18356694/198143033-9dc9a5c5-78d7-4311-9fd1-03f0e8ee8e31.png) I'm wondering if the reason we're not seeing this is there's some change in font that's occurring, which is triggering a clear? Also quick confirm if you're still seeing this on whatever your latest Windows build and Terminal version? Sorry it's been so long 😬
Author
Owner

@ghost commented on GitHub (Oct 30, 2022):

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

@ghost commented on GitHub (Oct 30, 2022): This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for **4 days**. It will be closed if no further activity occurs **within 3 days of this comment**.
Author
Owner

@patrick330602 commented on GitHub (Nov 2, 2022):

I just check it today, the problem still exists, and find some more information possinly related to the bug: if I use Japanese as the language for non-Unicode program the problem will show up, but using English do not have this issue it seems.

Also the content requested are here: https://git.pigeons.cloud/-/snippets/1

@patrick330602 commented on GitHub (Nov 2, 2022): I just check it today, the problem still exists, and find some more information possinly related to the bug: if I use Japanese as the language for non-Unicode program the problem will show up, but using English do not have this issue it seems. Also the content requested are here: https://git.pigeons.cloud/-/snippets/1
Author
Owner

@carlos-zamora commented on GitHub (Nov 2, 2022):

Removed "Needs-Attention". Someone on the team will take a closer look at this. Adding to current milestone so that we take time to investigate it. :)

@carlos-zamora commented on GitHub (Nov 2, 2022): Removed "Needs-Attention". Someone on the team will take a closer look at this. Adding to current milestone so that we take time to investigate it. :)
Author
Owner

@wonsuc commented on GitHub (Feb 11, 2025):

This suddenly started to happen to me too... @patrick330602 Did you find any solution for it?

@wonsuc commented on GitHub (Feb 11, 2025): This suddenly started to happen to me too... @patrick330602 Did you find any solution for it?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#12959