[CMD] CHOICE command needs to handle pipe input without getting stuck in timeout

This fixes cmd_winetest hanging on the echo Y | choice /C ABCXYZ /D A /T 2 test.

- Reads the first character from stdin if stdin is not connected to a real console.
- Ensures the timeout never goes negative if there is a problem reading stdin.
This commit is contained in:
Whindmar Saksit
2026-07-18 18:42:11 +02:00
parent 0943343296
commit e7eb740583
+12 -2
View File
@@ -52,7 +52,13 @@ GetCharacterTimeout (LPTCH ch, DWORD dwMilliseconds)
return GC_TIMEOUT;
//otherwise get the event
ReadConsoleInput (hInput, &lpBuffer, 1, &dwRead);
lpBuffer.EventType = !KEY_EVENT;
if (!ReadConsoleInput (hInput, &lpBuffer, 1, &dwRead) && GetLastError () == ERROR_INVALID_HANDLE)
{
*ch = '\0';
if (ReadFile(hInput, ch, 1, &dwRead, NULL))
return GC_KEYREAD;
}
//if the event is a key pressed
if ((lpBuffer.EventType == KEY_EVENT) &&
@@ -315,7 +321,11 @@ CommandChoice (LPTSTR param)
amount = nTimeout*1000;
loop:
GCret = GetCharacterTimeout (&Ch, amount - (GetTickCount () - clk));
nTimeout = amount - (GetTickCount () - clk);
if (nTimeout < 0)
GCret = GC_TIMEOUT;
else
GCret = GetCharacterTimeout (&Ch, nTimeout);
switch (GCret)
{