in reply to Pipes and IO::Select's method can_write()
You shouldn't use print with select. Had you used sysrwite, I bet it would have returned "successfully wrote 0 bytes" (defined and == 0). In other words, the child had ended. (Well, technically, the child has closed its STDIN, but it did that when it ended.)
Try
my $msg = "msg\n"; foreach my $w (IO::Select->new($wh)->can_write()) { my $rv = syswrite($w, $msg, length($msg)); if (not defined $rv) { die("Unable to send data to child\n"); } if (not $rv) { warn("Child is no longer accepting input\n"); $w_sel->remove($w); next; } if ($rv != length($msg)) { warn("Pipe is full. We'd normally call select again\n"); next; } print "Successfully sent message to the child\n"; }
Don't forget to reap your children with waitpid.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Pipes and IO::Select's method can_write()
by almut (Canon) on Feb 02, 2007 at 18:43 UTC | |
by ikegami (Patriarch) on Feb 02, 2007 at 18:56 UTC | |
by sgt (Deacon) on Feb 03, 2007 at 22:27 UTC | |
by almut (Canon) on Feb 02, 2007 at 20:44 UTC | |
by ikegami (Patriarch) on Feb 02, 2007 at 21:09 UTC | |
by sgt (Deacon) on Feb 02, 2007 at 23:14 UTC | |
by tye (Sage) on Feb 02, 2007 at 23:49 UTC | |
|