From 160b4e6e05e2cb9a2fa4ed6de203b4be754e4a83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Thu, 7 Mar 2019 04:33:54 +0200 Subject: [PATCH] MXS-2368: Fix reading of non-tty input The password input only worked if stdin was a TTY. This was caused by the fact that the readline-sync library only worked for TTYs. --- maxctrl/lib/common.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/maxctrl/lib/common.js b/maxctrl/lib/common.js index 379508d42..4003ac19c 100644 --- a/maxctrl/lib/common.js +++ b/maxctrl/lib/common.js @@ -50,9 +50,14 @@ module.exports = function() { // No password given, ask it from the command line if (argv.p == '') { - argv.p = readlineSync.question('Enter password: ', { - hideEchoBack: true - }) + if (process.stdin.isTTY) { + argv.p = readlineSync.question('Enter password: ', { + hideEchoBack: true + }) + } else { + var line = fs.readFileSync(0) + argv.p = line.toString().trim() + } } // Split the hostnames, separated by commas