{"record":{"id":"81f45bfad3e0cc16","repo":"apache/pulsar","slug":"cannot-use-stdin-e-execute-command-and-f-fi","errorCode":null,"errorMessage":"Cannot use stdin, -e/--execute-command and -f/--filename option at the same time","messagePattern":"Cannot use stdin, -e/--execute-command and -f/--filename option at the same time","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-client-tools/src/main/java/org/apache/pulsar/shell/PulsarShell.java","lineNumber":473,"sourceCode":"                return;\n            }\n        }\n    }\n\n    private boolean isNonInteractiveMode() {\n        boolean commandOk = true;\n        if (mainOptions.inlineCommand != null) {\n            if (mainOptions.readFromStdin\n                    || mainOptions.filename != null) {\n                commandOk = false;\n            }\n        } else if (mainOptions.readFromStdin\n                && mainOptions.filename != null) {\n            commandOk = false;\n        }\n\n        if (!commandOk) {\n            throw new IllegalArgumentException(\"Cannot use stdin, -e/--execute-command \"\n                    + \"and -f/--filename option at the same time\");\n        }\n        return mainOptions.filename != null || mainOptions.readFromStdin || mainOptions.inlineCommand != null;\n    }\n\n    private void printExecutingCommands(Terminal terminal,\n                                        CommandsInfo commandsInfo,\n                                        boolean printExecuted) {\n        if (commandsInfo == null) {\n            return;\n        }\n        terminal.puts(InfoCmp.Capability.clear_screen);\n        terminal.flush();\n        int index = 1;\n        if (printExecuted) {\n            for (CommandsInfo.ExecutedCommandInfo executedCommand : commandsInfo.executedCommands) {\n                String icon = executedCommand.ok ? CHECKMARK : XMARK;\n                final String ansiLog = new AttributedStringBuilder()","sourceCodeStart":455,"sourceCodeEnd":491,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client-tools/src/main/java/org/apache/pulsar/shell/PulsarShell.java#L455-L491","documentation":"PulsarShell's non-interactive mode requires exactly one input source for commands: stdin, -e/--execute-command (inline), or -f/--filename. isNonInteractiveMode() throws IllegalArgumentException when these are combined (e.g. both stdin and a filename) or the combination is otherwise invalid.","triggerScenarios":"Invoking the shell with -f <file> while also piping commands via stdin; combining -e with -f; piping into the shell while also passing an inline command.","commonSituations":"CI wrappers that both pipe a script and pass -f; shell aliases appending -e while the caller pipes input; accidental double input from a generated command line.","solutions":["Choose one input source: keep -f and remove piped stdin, or keep the pipe and drop -f.","If combining is intended, concatenate the commands into a single file or a single -e string.","Review the wrapper script/alias so it does not silently add a second input mechanism."],"exampleFix":"// before\necho 'admin topics list t' | pulsar-shell -f commands.conf\n// after\npulsar-shell -f commands.conf        // or pipe only, not both","handlingStrategy":"validation","validationCode":"// bash: ensure at most one input source\nSRC=0; [ -n \"$FILE\" ] && SRC=$((SRC+1)); [ -n \"$EXEC\" ] && SRC=$((SRC+1)); [ ! -t 0 ] && SRC=$((SRC+1)); [ \"$SRC\" -le 1 ] || { echo 'use only one of stdin, -e, -f'; exit 1; }","typeGuard":"function singleInputSource(opts) { return [opts.filename, opts.inlineCommand, opts.readFromStdin].filter(Boolean).length <= 1; }","tryCatchPattern":"try { shell.run(args); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith(\"Cannot use stdin\")) { /* rebuild args with one input source */ } else throw e; }","preventionTips":["Pick one command source per shell invocation: -e, -f, or piped stdin.","Audit wrapper scripts/aliases for hidden -e or -f additions.","In CI, prefer -f with a prepared commands file instead of piping."],"tags":["cli","shell","validation","mutually-exclusive"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}