CliDriver
- execute and control subprocesses with Expect
package require CliDriver
set p [CliDriver::Spawn #auto telnet localhost]
set count 0
set timeout 5
$p expect {
"*assword*:*" {
$p send "password\n"
exp_continue
}
"*ogin*:*" {
$p send "user\n"
exp_continue
}
"*user@host*" {
# done
}
timeout {
incr count
if {$count > 3} {
error "Timed out during login procedure."
}
exp_continue
}
}
The CliDriver
API is an object-oriented wrapper around expect
(1). It allows
you to automate shell sessions by launching and controlling interactive command
line applications from a Tcl script.
The main goal of the module is to alleviate the need for juggling with spawn ids and to encapsulate and simplify initialization sequences and subprocess management.
method expect
??-opts? pat1 body1? ... ?-opts? patn bodyn
expect
call described in expect
(1) but
is always bound to the subprocess associated with this object.method send
?-flags? string
send
call described in expect
(1) but
is always bound to the subprocess associated with this object.method close
method kill
method match_max
?size?spawn_id
associated with
this object.method pid
method process_exists
method terminate
Inherits all methods from CliDriver::Core
.
constructor
cmd ?arg arg ...?Inherits all methods from CliDriver::Core
.
constructor
?arg arg ...? host
telnet
command installed on the system and pass on any additional
arguments unmodified.Inherits all methods from CliDriver::Core
.
constructor
?arg arg ...? user@host
ssh
command installed on the system and pass on any additional
arguments unmodified.Inherits all methods from CliDriver::Core
.
constructor
?-baud
int? ?-parity
bool? ?-data_bits
int? ?-stop_bits
int? port
/dev/ttyS0
.Deleting a driver object that is associated with an active process, using
itcl::delete object
, will implicitely terminate the process.
expect
(1), itcl
(3)