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

Does anyone know why I might get an error when I try to close STDIN, STDOUT, and STDERR in a child process? I get this error: child process STDIN is not a real system file handle thanks...

Replies are listed 'Best First'.
Re: Can't close STDIN/STDOUT/STDERR
by salva (Canon) on Feb 09, 2010 at 21:17 UTC
    That message looks familiar to me ;-)

    Well, anyway, it means that instead of a real system file handle, you are using a faked one, usually something derived from Tie::Handle that is not connected to a real file. Tied file handles work fine as long as you stay inside the Perl process but you can not pass them to new processes because they do not exists at the operative system level.

      I'm really confused... I think I need to close the ACTUAL STDOUT/in/err because I'm trying to run a CGI script that takes a very long time to process. I want the parent to return an HTML confirmation page after it waits 30 seconds (in case the child finishes quickly).
        As ikegami has already toll you, reopen STDIN/STDOUT/STDERR to /dev/null.

        Though, until you get your program working right, it would be probably better to redirect STDOUT/STDERR to some file you can read (i.e. /tmp/out).

Re: Can't close STDIN/STDOUT/STDERR
by ikegami (Patriarch) on Feb 09, 2010 at 21:09 UTC
    That message does not appear in the Perl distribution. Maybe if you told us what's producing it.

      Ah! It appears to originate from Net::OpenSSH. (Thanks Google)

      Anyway, it's a fair warning. Programs expect to be provided a STDIN, STDOUT and STDERR, and you don't provide them. Don't close them. Instead, redirect them to /dev/null.

        I tried that (redirect to /dev/null) and it broke my program... I'm not well-versed enough in Perl to know why. Could you give me an example of how I should do it?
      } else { #Child die "cannot fork: $!" unless defined $child_pid; close(READER) or die "can't close READER: $!"; close(STDIN) or die "can't close STDIN: $!"; close(STDOUT) or die "can't close STDOUT: $!"; close(STDERR) or die "can't close STDERR: $!";
        I seriously doubt that code is issuing the error. One of those handles would have to use magic Google didn't find, or some Perl functions would have been replaced by some module Google didn't find. Neither are likely.