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 djpeg's TWO_FILE_COMMANDLINE mode, when no -outfile switch was given, it expects exactly two positional file arguments (input and output). If file_index != argc-2 the count is wrong, this message prints, and usage() exits. This branch is the missing-output-file case (no -outfile).

Source

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

   */
  jpeg_set_marker_processor(&cinfo, JPEG_COM, print_text_marker);
  jpeg_set_marker_processor(&cinfo, JPEG_APP0 + 12, print_text_marker);

  /* 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.
   * (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 */

View on GitHub (pinned to 45ab8f4308)

Solutions

  1. Provide exactly one input and one output positionally: djpeg in.jpg out.ppm.
  2. Or use -outfile <path> with a single input positional.
  3. If stdout output is required, use a build without TWO_FILE_COMMANDLINE or redirect the single output to /dev/stdout.

Example fix

# before: only input, no output (TWO_FILE_COMMANDLINE build)
djpeg in.jpg
# after
djpeg in.jpg out.ppm
# or
djpeg -outfile out.ppm in.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 0 ] && [ "${#pos[@]}" -ne 2 ] && { echo 'djpeg needs exactly one input and one output file' >&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 'supply input + output (or use -outfile)'; exit 1; }
fi

Prevention

When it happens

Trigger: Running djpeg with no -outfile and a positional count other than exactly two (e.g. djpeg in.jpg with only the input, or three+ files).

Common situations: Assuming djpeg writes to stdout when TWO_FILE_COMMANDLINE is defined; forgetting the output argument; glob expansion to multiple inputs.

Related errors


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