[Pdx-pm] Reading process output fails prematurely?

Michael G Schwern schwern at pobox.com
Thu Mar 5 02:50:52 PST 2009

Scott Garman wrote:
> Hello,
> I'm writing a simple test program that does something I've done many
> times with perl. It executes a long-running process and performs
> blocking reads on the stdout of that process. Like so:
> open(EVENTS, "| /usr/local/sbin/udevmonitor");

That means EVENTS is piping input into udevmonitor.  You want to read output.
 You also want to make sure it open succeeded.  Finally, use a lexical
filehandle just because there's no reason to muck with global filehandles any

  my $udevmonitor = "/usr/local/sbin/udevmonitor";
  open(my $events, "$udevmonitor |") or die "Can't open $udevmonitor: $!";
  while (my $line = <$events>) {
         print "I see: $line";

> When udevmonitor starts, it immediately prints out three lines, then
> sits silently until it detects a udev event from the Linux kernel, which
> it faithfully prints out.
> Running the above snippet of code, however, starts udevemonitor as a
> subprocess, prints "I see: <blah>" for those first three lines of
> output, and then exits, leaving the udevmonitor process running in the
> background.

Are you sure you saw "I see:"?  Because there's no way it should have worked
as presented above, but you might have seen just udevmonitor's output.  Do you
have warnings on?

Robrt:   People can't win
Schwern: No, but they can riot after the game.

More information about the Pdx-pm-list mailing list