From 27a0f9b2036680564ef6dfa54f3961af221cbc50 Mon Sep 17 00:00:00 2001 From: Matthew Stickney Date: Mon, 21 May 2018 23:24:34 -0400 Subject: [PATCH] Disable input echo on the console, not stdin. When data is piped to psql, a handle to stdin will no longer be a handle to the console; SetConsoleMode will fail, and prompt input will be echoed to the screen. Instead, use CreateFile to get a handle to the console's input buffer by opening CONIN$, and set the console mode there. Prompt input is already being read from CONIN$, so now prompt-related I/O modifications alter the same buffer. the same buffer. consistently. --- src/port/sprompt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/port/sprompt.c b/src/port/sprompt.c index 70dfa69d7b..f57b49bd3a 100644 --- a/src/port/sprompt.c +++ b/src/port/sprompt.c @@ -112,7 +112,7 @@ simple_prompt(const char *prompt, char *destination, size_t destlen, bool echo) if (!echo) { /* get a new handle to turn echo off */ - t = GetStdHandle(STD_INPUT_HANDLE); + t = CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); /* save the old configuration first */ GetConsoleMode(t, &t_orig); @@ -164,6 +164,7 @@ simple_prompt(const char *prompt, char *destination, size_t destlen, bool echo) { /* reset to the original console mode */ SetConsoleMode(t, t_orig); + CloseHandle(t); fputs("\n", termout); fflush(termout); } -- 2.16.2.windows.1