From afcc027da77f2285eda4c018348a3794c667581d Mon Sep 17 00:00:00 2001 From: Brent Cook Date: Sat, 5 Dec 2015 22:14:42 -0600 Subject: only set the console mode if stdin is a console (not a pipe) This allows piping commands and running from a cygwin console. --- crypto/compat/ui_openssl_win.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'crypto') diff --git a/crypto/compat/ui_openssl_win.c b/crypto/compat/ui_openssl_win.c index 13e93bc..aaab60b 100644 --- a/crypto/compat/ui_openssl_win.c +++ b/crypto/compat/ui_openssl_win.c @@ -301,27 +301,39 @@ open_console(UI *ui) tty_in = stdin; tty_out = stderr; - HANDLE handle = GetStdHandle(STD_INPUT_HANDLE); - if (handle != INVALID_HANDLE_VALUE) - return GetConsoleMode(handle, &console_mode); + HANDLE handle = (HANDLE)_get_osfhandle(STDIN_FILENO); + if (handle != INVALID_HANDLE_VALUE) { + if (GetFileType(handle) == FILE_TYPE_CHAR) + return GetConsoleMode(handle, &console_mode); + else + return 1; + } return 0; } static int noecho_console(UI *ui) { - HANDLE handle = GetStdHandle(STD_INPUT_HANDLE); - if (handle != INVALID_HANDLE_VALUE) - return SetConsoleMode(handle, console_mode & ~ENABLE_ECHO_INPUT); + HANDLE handle = (HANDLE)_get_osfhandle(STDIN_FILENO); + if (handle != INVALID_HANDLE_VALUE) { + if (GetFileType(handle) == FILE_TYPE_CHAR) + return SetConsoleMode(handle, console_mode & ~ENABLE_ECHO_INPUT); + else + return 1; + } return 0; } static int echo_console(UI *ui) { - HANDLE handle = GetStdHandle(STD_INPUT_HANDLE); - if (handle != INVALID_HANDLE_VALUE) - return SetConsoleMode(handle, console_mode); + HANDLE handle = (HANDLE)_get_osfhandle(STDIN_FILENO); + if (handle != INVALID_HANDLE_VALUE) { + if (GetFileType(handle) == FILE_TYPE_CHAR) + return SetConsoleMode(handle, console_mode); + else + return 1; + } return 0; } -- cgit v1.2.3-55-g6feb