in reply to Bad file descriptor when trying to close file handle

> But when I invoke the module from Linux Perl v5.34.0,

another guess: Are multiple processes simultaneously writing at or even deleting, renaming or removing the file?

Bad file descriptor is an OS/FS error, not Perl.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^2: Bad file descriptor when trying to close file handle
by ikegami (Patriarch) on Mar 03, 2022 at 14:42 UTC

    No, changes to the directory entry that was used to open the file (incl renaming and deleting) would not result in that error.

    Unix: Doing these things has no effect on the file, to which one can continue writing. It would not produce an error at all.

    Windows: File handles opened by Perl don't even allow those operations to occur. (This is standard.)

      I tested it out, you are right, the only way to reproduce this was closing the same FH twice. (at least I think, Ubuntu is giving me German error messages)°

      > to which one can continue writing.

      well kind of, printing to an unlinked file in ">>" mode seems to do nothing, but no error message either.

      (Tho I only did a quick test in the debugger...)

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

      °) it's unfortunate we can't add these kind of errors to perldiag

        well kind of, printing to an unlinked file in ">>" mode seems to do nothing, but no error message either.

        It might seem to you that it does nothing, but that's not the case. It does what I said it does: It writes to the file as it always does.

        Open the file twice, once for reading and once for writing. Then delete the directory entry you used to open the file, then write to it, then read from it. You'll see it's there.