iOfficeAI/OfficeCLI · error · ArgumentException
batch: --commands and --input are mutually exclusive. Pick o
Error message
batch: --commands and --input are mutually exclusive. Pick one source.
What it means
Thrown by the `batch` command when both --commands (inline JSON) and --input (file path) are supplied. The two are alternative input sources; providing both is ambiguous so an ArgumentException rejects it before any read happens (line 210-212).
Source
Thrown at src/officecli/CommandBuilder.Batch.cs:211
// EOF instantly (no payload → no warning); a pipe carrying a
// real second payload has data ready (warn); an open-but-idle
// pipe times out and is treated as no payload — batch never
// reads stdin on this path anyway, so nothing is lost. The
// possibly-blocked Peek thread is abandoned; the process
// exits normally.
try
{
var stdinPeek = System.Threading.Tasks.Task.Run(() =>
{
try { return StdIn.Peek() != -1; }
catch { return false; }
});
stdinHasInput = stdinPeek.Wait(TimeSpan.FromMilliseconds(50)) && stdinPeek.Result;
}
catch { /* keep IsInputRedirected verdict */ }
}
if (inlineCommands != null && inputFile != null)
throw new ArgumentException(
"batch: --commands and --input are mutually exclusive. Pick one source.");
// '--input -' explicitly opts INTO stdin — don't emit the
// "stdin will be ignored" warning in that case, since stdin
// is exactly what will be read.
var inputIsStdinAlias = inputFile != null && inputFile.Name == "-";
if ((inlineCommands != null || (inputFile != null && !inputIsStdinAlias)) && stdinHasInput
&& Environment.GetEnvironmentVariable("OFFICECLI_BATCH_ALLOW_STDIN_REDIRECT") == null)
{
Console.Error.WriteLine(
"Warning: batch is reading from --commands/--input but stdin is also redirected; "
+ "stdin will be ignored. Pass only one source to silence this warning, or set "
+ "OFFICECLI_BATCH_ALLOW_STDIN_REDIRECT=1.");
}
if (inlineCommands != null)
{
jsonText = inlineCommands;
}
else if (inputFile != null)View on GitHub (pinned to 1ced45e900)
Solutions
- Choose one source: pass --commands for inline JSON, or --input for a file/stdin. Remove the other.
- For files/stdin use --input <file> or --input - (stdin alias); for inline use --commands only.
- If you need to merge, concatenate the JSON arrays into one source first.
Example fix
# before
officecli batch file.docx --commands '[{"command":"get"}]' --input ops.json
# after
officecli batch file.docx --input ops.json Defensive patterns
Strategy: validation
Validate before calling
// Ensure exactly one batch input source.
if (inlineCommands != null && inputFile != null)
throw new ArgumentException("Pass --commands OR --input, not both"); Type guard
// Guard: a single batch source is selected.
static bool SingleBatchSource(string? inline, string? file) =>
(inline != null) ^ (file != null) || (inline == null && file == null); Prevention
- Use mutually exclusive CLI construction (one variable, cleared when the other is set) in wrappers.
- Default to one source in scripts and never merge --commands from one call with --input from another.
When it happens
Trigger: `officecli batch file.docx --commands '[{...}]' --input ops.json`. inlineCommands != null && inputFile != null triggers the throw.
Common situations: A script defaults to --input but a caller also passes --commands; an agent pastes an inline array while a config file path is still wired in; copy-paste merges two invocations.
Related errors
- invalid_argument
- missing_argument
- Input file not found: {inputFile.FullName}
- invalid_value
- invalid_value
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/00d7892bc1db8e79.
Report an issue: GitHub.