in reply to Problems executing a (bioperl) script from another script

OK, I simplified things as much as I can to narrow down the problem. This works:
open( my $command_out, "-|", $command ); sleep 3; close $command_out;
and this does not:
open( my $command_out, "-|", $command ); close $command_out;
Why?
Isn't `close` suppose to block until the command is done?
Closing any piped filehandle causes the parent process to wait for the child to finish... (from open)

Replies are listed 'Best First'.
Re^2: Problems executing a (bioperl) script from another script
by graff (Chancellor) on Aug 14, 2010 at 05:37 UTC
    This is the last paragraph in the man page that you get when you run "perldoc -f close":
    Prematurely closing the read end of a pipe (i.e. before the process writing to it at the other end has closed it) will result in a SIGPIPE being delivered to the writer. If the other end can’t handle that, be sure to read all the data before closing the pipe.

    I think this is relevant to your case. You don't seem to be reading anything from the pipe file handle after you open it, so maybe you don't really want to use open( $fh, "-|", $command ) in this case -- use a system call instead.

    If you actually do need to read output from the command, just read from the file with the usual  while (<$fh>) {...} idiom, or use "slurp" mode on the pipe file handle. In either case, EOF will be detected when the sub-process finishes -- just don't close it before that happens.