in reply to close statement issue

I'm not sure if this is the main cause of the symptoms, it being that the code actually shown has some typos anyway, and might not be the "real" code (tm), but ...

When working with pipes it is advisable to wait for the subprocess to terminate before closing the pipe (e.g. by allowing the program to exit by default in this case). Also, use "or" and "and" rather than || and && when everything to the left is a complete statement for which the or and and is to operate on the truth value, otherwise it is apt to operate on only part of the statement (an error). For example:

use POSIX ":sys_wait_h"; my $mpid = open my $mh, "| /usr/sbin/sendmail" or die "$!"; print $mh << "EOF"; To: joe@here.com From: smith@here.com Subject: data subject message body here EOF close $mh or die "$!"; waitpid $mpid, 0;

-M

Free your mind

Replies are listed 'Best First'.
Re^2: close statement issue
by ysth (Canon) on Mar 02, 2007 at 08:11 UTC
      Huh? I first discovered waitpid precisely because it doesn't, at least on SUNOS with v 5.005 and I had sysadms asking me to do something about the zombies being left in the air when I closed the pipe and returned without wait.

      -M

      Free your mind

        I don't know what to tell you; it most certainly does in current perls, and based on the doc, did so in 5.005 too. Try this:
        $ perl -we'open FOO, q<| sh -c "sleep 5;exit 123"> or die; print "clos +ing:\n"; close FOO; print $? >> 8' closing: 123
        to verify that close() is waiting for the process to finish and putting its status in $?.

        (Update: removed lexical filehandle; I'd really like to see you try the above on your SunOS 5.005.)