apache/pulsar · error · IllegalArgumentException
Cannot use stdin, -e/--execute-command and -f/--filename opt
Error message
Cannot use stdin, -e/--execute-command and -f/--filename option at the same time
What it means
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.
Source
Thrown at pulsar-client-tools/src/main/java/org/apache/pulsar/shell/PulsarShell.java:473
return;
}
}
}
private boolean isNonInteractiveMode() {
boolean commandOk = true;
if (mainOptions.inlineCommand != null) {
if (mainOptions.readFromStdin
|| mainOptions.filename != null) {
commandOk = false;
}
} else if (mainOptions.readFromStdin
&& mainOptions.filename != null) {
commandOk = false;
}
if (!commandOk) {
throw new IllegalArgumentException("Cannot use stdin, -e/--execute-command "
+ "and -f/--filename option at the same time");
}
return mainOptions.filename != null || mainOptions.readFromStdin || mainOptions.inlineCommand != null;
}
private void printExecutingCommands(Terminal terminal,
CommandsInfo commandsInfo,
boolean printExecuted) {
if (commandsInfo == null) {
return;
}
terminal.puts(InfoCmp.Capability.clear_screen);
terminal.flush();
int index = 1;
if (printExecuted) {
for (CommandsInfo.ExecutedCommandInfo executedCommand : commandsInfo.executedCommands) {
String icon = executedCommand.ok ? CHECKMARK : XMARK;
final String ansiLog = new AttributedStringBuilder()View on GitHub (pinned to 820761864e)
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.
Example fix
// before echo 'admin topics list t' | pulsar-shell -f commands.conf // after pulsar-shell -f commands.conf // or pipe only, not both
Defensive patterns
Strategy: validation
Validate before calling
// bash: ensure at most one input source
SRC=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; } Type guard
function singleInputSource(opts) { return [opts.filename, opts.inlineCommand, opts.readFromStdin].filter(Boolean).length <= 1; } Try / catch
try { shell.run(args); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith("Cannot use stdin")) { /* rebuild args with one input source */ } else throw e; } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- '${DEFAULT_CONFIG}' can't be modified.
- ${paramName} cannot be bigger than <${maxValue}>!
- ${paramName} cannot be less than or equal to <0>!
- The value of ${paramName} can't be empty
- ${name} cannot be less than <${min}>!
AI-assisted analysis of apache/pulsar@820761864e (2026-09-06).
Data as JSON: /api/errors/81f45bfad3e0cc16.
Report an issue: GitHub.