Because you haven't emptied the pipe, which means that tasklist is blocked waiting to finish writing to it.
Just closing the pipe won't allow tasklist to end; the pipe won't close until it does. Deadlock.
The answer is to empty the pipe before closing it:
use strict; use warnings; use IO::Pipe; my $cmd = "tasklist"; my $pipe = IO::Pipe->new(); $pipe->reader($cmd); while (my $line = $pipe->getline()) { print $line; last if $line =~ /^smss/; } 1 while $pipe->getline; $pipe->close();
In reply to Re: IO::Pipe hangs
by BrowserUk
in thread IO::Pipe hangs
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |