Skip to content

Conversation

@fglock
Copy link
Owner

@fglock fglock commented Dec 18, 2025

Problem

When running ExifTool with JPERL_LARGECODE=refactor, the following error occurred:

Unsupported filehandle duplication: STDERR
        main at exiftool line 1483

This was caused by code like:

open SAVEERR, ">&STDERR";

Root Cause

IOOperator.openFileHandleDup() only supported numeric file descriptors (e.g., >&2), not named filehandles like >&STDERR.

Fix

Extended openFileHandleDup() to handle:

  • Standard handles by name: STDIN, STDOUT, STDERR (case-insensitive)
  • Other named filehandles via global IO table lookup

Testing

Added regression test src/test/resources/unit/filehandle_dup.t with 4 subtests:

  • Duplicating STDERR by name
  • Duplicating STDOUT by name
  • Duplicating by file descriptor number
  • Redirect and restore STDERR pattern (common idiom used by ExifTool)

Added support for duplicating named filehandles like STDERR, STDOUT,
and STDIN using the >&NAME syntax (e.g., open SAVEERR, '>&STDERR').

Previously, only numeric file descriptors were supported (e.g., >&2).
This caused 'Unsupported filehandle duplication: STDERR' errors when
running code that uses the common pattern of saving and restoring
standard handles.

The fix extends openFileHandleDup() to:
- Handle STDIN, STDOUT, STDERR by name (case-insensitive)
- Look up other named filehandles in the global IO table

Added regression test filehandle_dup.t with 4 subtests covering:
- Duplicating STDERR by name
- Duplicating STDOUT by name
- Duplicating by file descriptor number
- Redirect and restore STDERR pattern
@fglock fglock merged commit df291aa into master Dec 18, 2025
2 checks passed
@fglock fglock deleted the fix-filehandle-duplication branch December 18, 2025 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants