NAME

GTM::Run - run interactive processes


SYNOPSIS

   use GTM::Run;
   my $hdl = new GTM::Run ("mumps -direct");
   $hdl->expect(
        qr/GTM\>/,
        qr/^%.*/m,
        sub {
            die $_[1] if $_[2];
            shift->write ("D ^\%GO\n");
        }
   );


DESCRIPTION

This module is a helper-module for running interactive processes in a "expect"-like way.


METHODS

$handle = new GTM::Run ($command)

Creates a GTM::Run object. The $command is either a single string, which is then passed to a shell, or an arrayref, which is passed to the "execvp" function. If command is not a fully qualified command (ie: starts not with /) $ENV{gtm_dist} will be prepended.

$handle->close ()

Closes the command. This runs waitpid so be sure that your command will terminate. For mumps this means that "Halt\n" must be written before.

$handle->write ($data, ...)

writes $data to the process

$handle->debug ($bool)

writes regular expression debug-info to STDERR if enabled. Here an example:

    $self->expect(
        qr/^No globals selected/m,
        qr/^Header Label:/m,
        sub {
           ...
        },
   );

This writes:

  RE: (?m-xis:^No globals selected) == 0
  RE: (?m-xis:^Header Label:) == 1
  RE: match index == 1

if debugging is enabled.

$handle->expect ($re0, [$re1,...,] &cb [, $re .... &cb])

Waits for input that matches one of the given regular expressions. &cb will be invoked with three arguments: $class, $data, $reidx. $reidx is the index of the regular expression that matched.

A callback may die - close will be invoked and the die gets propagated. Subsequent callbacks within the same expect-call will be skipped.

$hdl->flush ()

Waits until the output buffer is empty.


SEE ALSO

GTM


AUTHOR

   Stefan Traby <stefan@hello-penguin.com>
   http://oesiman.de/gt.m/