jaa has asked for the wisdom of the Perl Monks concerning the following question:

Monks,

I recently upgraded from Perl 5.6.1 to Perl 5.8.3 and I am now getting a new warning from IO/File:

Filehandle STDIN reopened as GEN6 only for output at /usr/lib/perl/5.8/IO/File.pm line 70.

This happens because our Perl run harness uses open3() to execute a child process, passing its own STDIN to the child process. It then opens a file for logging output, which ends up getting issued the magic filenumber for STDIN - hence the warning about opening STDIN for output.

I guess I could open up a random file for input, before opening up the output log - but this feels ugly.

Is there a better way to ignore this warning, just in this curcumstance?

Regards & thanks,

Jeff

Replies are listed 'Best First'.
Re: New warnings Perl 5.8.3 in IO/File
by ysth (Canon) on Mar 23, 2004 at 10:50 UTC
    The warning is there to protect you. Don't leave one of the magic filenumbers closed if you expect to open more files, or Bad Things Will Result(TM). Opening a file ("/dev/null" or perhaps File::Spec::Functions::devnull()) is the correct thing to do.

      What Bad Things should I expect?

      STDIN has been passed to the child process that we are monitoring. The run harness opens the log file after it gets the child PID (otherwise I would simply have moved the logfile open before passing STDIN on to the child.)

      is there Another Way?

        I really don't understand from your descriptions exactly what your situation is. Some pseudocode (or real code) demonstrating what you are doing would help. Is there some problem with opening a dummy file just after closing STDIN?

        If you don't immediately reuse one of the reserved file descriptors after closing it, any future open of a file will accidentally get it, any code writing to the underlying file descriptor expecting it to be stdin/out/err will have trouble, code that tries to reopen the descriptor to a different handle will fail.