DrKLO/Telegram · error

%s: must name one input and one output file\n

Error message

%s: must name one input and one output file\n

What it means

In djpeg's TWO_FILE_COMMANDLINE mode, when -outfile WAS given, it expects exactly one positional file (the input). If file_index != argc-1 there are extra positional files, this message prints, and usage() exits. Same message string as the no-outfile branch but a different trigger (extra positionals alongside -outfile).

Source

Thrown at TMessagesProj/jni/mozjpeg/djpeg.c:571

   * the input file.
   * (Exception: tracing level set here controls verbosity for COM markers
   * found during jpeg_read_header...)
   */

  file_index = parse_switches(&cinfo, argc, argv, 0, FALSE);

#ifdef TWO_FILE_COMMANDLINE
  /* 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();
  }
#endif /* TWO_FILE_COMMANDLINE */

  /* Open the input file. */
  if (file_index < argc) {
    if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) {
      fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]);
      exit(EXIT_FAILURE);
    }

View on GitHub (pinned to 45ab8f4308)

Solutions

  1. When using -outfile, pass exactly one positional input: djpeg -outfile out.ppm in.jpg.
  2. Guard/quote globs to a single input, or loop invoking djpeg once per file.
  3. Remove stray trailing positional arguments.

Example fix

# before: -outfile plus two positionals
djpeg -outfile out.ppm in1.jpg in2.jpg
# after
djpeg -outfile out.ppm in1.jpg
Defensive patterns

Strategy: validation

Validate before calling

#!/bin/sh
has_outfile=0; pos=()
for a in "$@"; do case "$a" in -outfile) has_outfile=1;; -*) ;; *) pos+=("$a");; esac; done
[ "$has_outfile" -eq 1 ] && [ "${#pos[@]}" -ne 1 ] && { echo 'with -outfile, pass exactly one input file to djpeg' >&2; exit 1; }
djpeg "$@"

Type guard

// n/a: argv-count validation in the caller.

Try / catch

if ! djpeg "$@" 2>/tmp/e; then
  grep -q 'must name one input and one output file' /tmp/e && { echo 'remove extra positional files when using -outfile'; exit 1; }
fi

Prevention

When it happens

Trigger: Passing -outfile <path> together with two or more positional file arguments, or zero positionals: djpeg -outfile out.ppm in1.jpg in2.jpg.

Common situations: Shell glob producing multiple inputs; copy-pasting a two-positional command then adding -outfile without removing the second positional; leftover args in a wrapper script.

Related errors


AI-assisted analysis of DrKLO/Telegram@45ab8f4308 (2026-08-14). Data as JSON: /api/errors/c3f4a4f5582b606c. Report an issue: GitHub.