I know Rolands on vacation for 2 weeks but
if there is anyone out there that could help.
I've just started using Expect.pm for the first time
so it's taking some time.
The main problem I'm having with Expect.pm (or more than
likely my code) is the time it is taking to destroy/close and return.
Takes about 15 sec once the expect "exec ls>test.txt &\r"
is given. I've tried with other programs/commands as well.
I'm either missing something or this is normal for Expect.
The code below is just a test/learning script, it's using a Pty
but the time thing doesn't matter with or without using a Pty.
Believe me I've read and re-read everything I could find on
Expect.pm, I've tweaked with this little sample script till my mind
goes numb. I think I've tried every possible way of doing this.
Anyway I'm using v1.11, I've noticed in the pre-release v1.12
Roland says something about taking care of how long it takes
to destroy and expect object. Where can I get a copy of v1.12
to try?
#########################################
#!/usr/bin/perl
use Expect;
use IO::Pty;
require POSIX;
$pty = new IO::Pty;
POSIX::setsid();
my $tty = $pty->slave;
open(STDIN, "<&".fileno($tty));
open(STDOUT,">&".fileno($tty));
open(STDERR,">&STDOUT");
#will prompt for this later.
my $password = "xxxxxx\r";
my $prompt = '[\]\$\>\#]\s$';
my $command = Expect->spawn("su");
$command->log_file("log", "w");
###################################################
#$command->expect(10,
# [ '-re', 'word:\s$',
# sub { print $command->send("$password\r");
# exp_continue; } ],
#
# [ '-re',$prompt,
# sub { print $command->send("exec ls>test.txt &\r");
# } ],
# );
#######################################################
$command->expect(10, '-re', 'word:\s$');
print $command "$password\r";
$command->expect(10,'-re',$prompt);
print $command "exec ls>test.txt &\r";
###################################################
close($tty);
TIA
|