DrKLO/Telegram · error
%s: must name one input and one output file
Error message
%s: must name one input and one output file
What it means
In TWO_FILE_COMMANDLINE mode, when no -outfile switch was given, cjpeg expects exactly two positional file arguments (input and output). If file_index (the count of non-switch positionals after parsing) is not argc-2, the count is wrong and this message prints, then usage() exits. This branch covers the missing-output-file case.
Source
Thrown at TMessagesProj/jni/mozjpeg/cjpeg.c:718
*/
cinfo.in_color_space = JCS_RGB; /* arbitrary guess */
jpeg_set_defaults(&cinfo);
/* Scan command line to find file names.
* It is convenient to use just one switch-parsing routine, but the switch
* values read here are ignored; we will rescan the switches after opening
* the input file.
*/
file_index = parse_switches(&cinfo, argc, argv, 0, FALSE);
#ifdef TWO_FILE_COMMANDLINE
if (!memdst) {
/* Must have either -outfile switch or explicit output file name */
if (outfilename == NULL) {
if (file_index != argc - 2) {
fprintf(stderr, "%s: must name one input and one output file\n",
progname);
usage();
}
outfilename = argv[file_index + 1];
} else {
if (file_index != argc - 1) {
fprintf(stderr, "%s: must name one input and one output file\n",
progname);
usage();
}
}
}
#else
/* Unix style: expect zero or one file name */
if (file_index < argc - 1) {
fprintf(stderr, "%s: only one input file\n", progname);
usage();
}View on GitHub (pinned to 45ab8f4308)
Solutions
- Provide exactly one input and one output file positionally when not using -outfile, e.g. cjpeg in.ppm out.jpg.
- Alternatively use -outfile <path> and pass a single input positional.
- If you need stdout output, use a build without TWO_FILE_COMMANDLINE or redirect the single output to /dev/stdout.
Example fix
# before: only input given, no output cjpeg in.ppm # after cjpeg in.ppm out.jpg # or cjpeg -outfile out.jpg in.ppm
Defensive patterns
Strategy: validation
Validate before calling
#!/bin/sh
# Ensure exactly two positionals when no -outfile is present (TWO_FILE_COMMANDLINE build)
has_outfile=0; pos=()
for a in "$@"; do case "$a" in -outfile) has_outfile=1;; -*) ;; *) pos+=("$a");; esac; done
[ "$has_outfile" -eq 0 ] && [ "${#pos[@]}" -ne 2 ] && { echo 'need exactly one input and one output file' >&2; exit 1; }
cjpeg "$@" Type guard
// n/a: argv-count validation in the caller.
Try / catch
if ! cjpeg "$@" 2>/tmp/e; then
grep -q 'must name one input and one output file' /tmp/e && { echo 'supply input + output (or use -outfile)'; exit 1; }
fi Prevention
- In wrapper scripts, separate options from positionals explicitly and assert the positional count before exec.
- Default to -outfile for explicit output to avoid ambiguity.
- Document which build flavor (TWO_FILE_COMMANDLINE) is deployed.
When it happens
Trigger: Calling cjpeg with no -outfile and not exactly two positional arguments: zero, one, or three+ positional file names (e.g. only an input file, or input plus multiple outputs).
Common situations: Expecting cjpeg to write to stdout when TWO_FILE_COMMANDLINE is defined (it does not in this mode); forgetting the output argument; shell glob expanding to many files; piping assumptions.
Related errors
- %s: only one input file
- %s: must name one input and one output file
- %s: missing argument for trellis-dc-ver-weight
- %s: unknown option '%s'
- %s: can't set quality ratings
AI-assisted analysis of DrKLO/Telegram@45ab8f4308 (2026-08-14).
Data as JSON: /api/errors/75a5a414a4de30bf.
Report an issue: GitHub.