On Sep 27, Matthew Blacklow said:

>What I need to do is capture the screen output of this process into a string
>variable so that it can latter be manipulaterd. ie. capture the STDOUT.

Several options:

  # qx() and `` are the same
  $output = `prog arg1 arg2`;
  $output = qx(prog arg1 arg2);

  # get lines of output, not one lone string
  @output = `prog arg1 arg2`;
  @output = qx(prog arg1 arg2);

  # open a pipe, and go line-by-line
  open OUTPUT, "prog arg1 arg2 |";
  while (<OUTPUT>) {
    ...
  }
  close OUTPUT;

  # or get it all at once
  open OUTPUT, "prog arg1 arg2 |";
  {
    local $/;  # read all the content at once
    $output = <OUTPUT>;
  }
  close OUTPUT;

Of course, all of these should have error-checking:

  $x = `...` or die "can't run ...: $!";

  open OUTPUT, "... |" or die "can't run ...: $!";

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to