{"record":{"id":"efbf4b3a92fe3f23","repo":"elastic/elasticsearch","slug":"unable-to-read-from-standard-input-is-standard-in","errorCode":null,"errorMessage":"unable to read from standard input; is standard input open and a tty attached?","messagePattern":"unable to read from standard input; is standard input open and a tty attached\\?","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"libs/cli-terminal/src/main/java/org/elasticsearch/cli/terminal/Terminal.java","lineNumber":140,"sourceCode":"     * <p> Defaults to {@link Verbosity#NORMAL}.\n     */\n    public void setVerbosity(Verbosity verbosity) {\n        this.currentVerbosity = verbosity;\n    }\n\n    /**\n     * Return the current verbosity level of this terminal.\n     */\n    public Verbosity getVerbosity() {\n        return currentVerbosity;\n    }\n\n    private char[] read(String prompt) {\n        errWriter.print(prompt); // prompts should go to standard error to avoid mixing with list output\n        errWriter.flush(); // flush to ensure it is seen\n        final char[] line = readLineToCharArray(reader);\n        if (line == null) {\n            throw new IllegalStateException(\"unable to read from standard input; is standard input open and a tty attached?\");\n        }\n        return line;\n    }\n\n    /** Reads clear text from the terminal input. See {@link Console#readLine()}. */\n    public String readText(String prompt) {\n        return new String(read(prompt));\n    }\n\n    /** Reads password text from the terminal input. See {@link Console#readPassword()}}. */\n    public char[] readSecret(String prompt) {\n        return read(prompt);\n    }\n\n    /** Returns a Reader which can be used to read directly from the terminal using standard input. */\n    public final Reader getReader() {\n        return reader;\n    }","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/libs/cli-terminal/src/main/java/org/elasticsearch/cli/terminal/Terminal.java#L122-L158","documentation":"Thrown by Terminal.read when the underlying reader returns null, meaning EOF was reached before any input was read. The Terminal class wraps System.in via a Console-like reader, and a null read indicates stdin is closed, redirected from /dev/null, or detached from a tty. The IllegalStateException is unrecoverable for interactive prompts (keystore password, confirmation) because there is no way to obtain the input the prompt needs.","triggerScenarios":"Running an interactive CLI command under cron, systemd without a TTY, `nohup`, or with stdin redirected from `/dev/null`. Piping a non-interactive stream into a command that expects a secret prompt. Running inside a container without `-it`.","commonSituations":"Automating `elasticsearch-keystore create` without supplying stdin. CI shells that close stdin by default. `ssh host command` (no PTY allocated) invoking an interactive prompt.","solutions":["Provide the input non-interactively via stdin: `printf 'secret\\n' | bin/elasticsearch-keystore add-file ...`.","Allocate a TTY when running remotely: `ssh -t` or `docker run -it`.","Use the command's non-interactive flag (e.g. `--stdin` for keystore add) so it does not prompt.","For daemons, ensure the startup environment has stdin attached or redirected from a controlled source."],"exampleFix":"# before (no tty)\nssh es-host 'bin/elasticsearch-keystore add-file x.file'\n# after\nssh -t es-host 'bin/elasticsearch-keystore add-file x.file'\n# or feed stdin directly\nssh es-host 'bin/elasticsearch-keystore add --stdin -x setting < /path/to/value'","handlingStrategy":"validation","validationCode":"if (System.console() == null && requiresInteractiveInput) {\n    throw new IllegalStateException(\"No TTY attached; pass input via stdin or use --stdin flag.\");\n}","typeGuard":"static boolean hasInteractiveStdin() {\n    return System.console() != null;\n}","tryCatchPattern":"try {\n    char[] secret = terminal.readSecret(\"Password: \");\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"standard input\")) {\n        // fall back to reading from a provided file/env var instead of prompting\n    } else throw e;\n}","preventionTips":["Detect `System.console() == null` before prompting and switch to non-interactive input.","Prefer `--stdin` flags that read secrets from a pipe rather than a TTY.","In CI/SSH, allocate a PTY (`ssh -t`, `docker run -it`) when prompting is unavoidable."],"tags":["cli","terminal","stdin","interactive","tty"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}