mirror of
https://github.com/ApfelTeeSaft/reactos.git
synced 2026-08-26 19:33:31 +00:00
[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:
+12
-2
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user