ReadConsoleOutputAttribute returns zeros in the attribute buffer #12020

Open
opened 2026-01-31 03:04:09 +00:00 by claunia · 0 comments
Owner

Originally created by @Maximus5 on GitHub (Jan 12, 2021).

Environment

Windows build number: 10.0.18363.1256
ConEmu: 210111

Steps to reproduce

  1. Run it as: conemu64.exe -basic -run cmd.exe /k wsl.exe
  2. WSL prompt appears, type exit
  3. cmd.exe prompt appears, but the first 4 characters are invisible. The reason is that ReadConsoleOutputAttribute returns malformed data (all zeros in attributes array).

Expected behavior

ReadConsoleOutputAttribute returns 7-s in the attributes array.

Actual behavior

ReadConsoleOutputAttribute returns 0-s in the attributes array.

Details

Sample code used in ConEmu to read attribute data

#define ROWID_USED_CELLS 4
WORD  nAttrs[ROWID_USED_CELLS];
const COORD crLeft = {0, nRow};
DWORD nRead = 0;
if (!ReadConsoleOutputAttribute(hConOut, nAttrs, ROWID_USED_CELLS, crLeft, &nRead) || (nRead != ROWID_USED_CELLS))
   return false;

So, on exit from wsl.exe back to cmd.exe prompt (we started it as cmd /k wsl.exe), ReadConsoleOutputAttribute returns TRUE, nRead is equal to 4, but nAttrs is {0,0,0,0}.

For now, I found the workaround - ReadConsoleOutputW works properly, it returns cell attribute 7.

Originally created by @Maximus5 on GitHub (Jan 12, 2021). # Environment ```none Windows build number: 10.0.18363.1256 ConEmu: 210111 ``` # Steps to reproduce 1. Run it as: conemu64.exe -basic -run cmd.exe /k wsl.exe 2. WSL prompt appears, type exit 3. cmd.exe prompt appears, but the first 4 characters are invisible. The reason is that ReadConsoleOutputAttribute returns malformed data (all zeros in attributes array). # Expected behavior ReadConsoleOutputAttribute returns 7-s in the attributes array. # Actual behavior ReadConsoleOutputAttribute returns 0-s in the attributes array. # Details Sample code used in ConEmu to read attribute data ``` #define ROWID_USED_CELLS 4 WORD nAttrs[ROWID_USED_CELLS]; const COORD crLeft = {0, nRow}; DWORD nRead = 0; if (!ReadConsoleOutputAttribute(hConOut, nAttrs, ROWID_USED_CELLS, crLeft, &nRead) || (nRead != ROWID_USED_CELLS)) return false; ``` So, on exit from wsl.exe back to cmd.exe prompt (we started it as `cmd /k wsl.exe`), **ReadConsoleOutputAttribute** returns **TRUE**, **nRead** is equal to **4**, but **nAttrs** is **{0,0,0,0}**. For now, I found the workaround - **ReadConsoleOutputW** works properly, it returns cell attribute 7.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#12020