Mnet::Expect - Create Expect objects with Mnet::Log support


    # refer to SEE ALSO section for other Mnet::Expect modules
    use Mnet::Expect;

    # spawn Expect telnet process connected to specified host
    my $expect = Mnet::Expect->new({ spawn => "telnet" });

    # access underlying Expect methods, refer to perldoc Expect

    # gracefully close spawned Expect process


Mnet::Expect can be used to spawn Expect processes, which can be used to programmatically control interactive terminal sessions, with support for Mnet options and logging.

Refer to the perl Expect module for more information. Also refer to the Mnet::Expect::Cli and Mnet::Expect::Cli::Ios modules.


Mnet::Expect implements the methods listed below.


    $expect = Mnet::Expect->new(\%opts)

This method can be used to create new Mnet::Expect objects.

The following input opts may be specified:

    log_expect  default session debug, refer to log_expect method
    log_id      refer to perldoc Mnet::Log new method
    raw_pty     undef, can be set 0 or 1, refer to perldoc Expect
    spawn       command and args array ref, or space separated string
    winsize     specify session rows and columns, default 99999x999

An error is issued if there are spawn problems.

For example, the following will spawn an telnet expect session to a device:

    my $expect = Mnet::Expect->new({ spawn => "telnet" });

Note that all connected session activity is logged for debugging, refer to the Mnet::Log module for more information.



Attempt to call hard_close for the current Mnet::Expect objects Expect session, and send a kill signal if the process still exists.

The Expect object associated with the current Mnet::Expect object will be set to undefined. Refer also to the expect method documented below.



Returns the underlying expect object used by this module, for access to fetures that may not be supported directly by Mnet::Expect modules. Refer to the Expect module for more information.


    $prior = $expect->log_expect($level)

Use this method to set a new log_expect level for expect session traffic. The prior log_expect value will be returned.

The new log_expect level can be set to debug, info, or undefined. An undefined log_expect disables the logging of expect session traffic, which might be useful to keep sensitive data out of log outputs.

The default log level for expect session traffic is debug.

An invalid input log_expect level results in an error.


Mnet::Expect does not include iteself include support for Mnet::Test functionality. This is a low level module that spawns expect sessions but does not know how to talk to devices. Any desired test fucntionality would need to be provided by the calling script.