Skip to content

Instantly share code, notes, and snippets.

@shalk
Created May 15, 2014 06:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shalk/8e6d5c30244b21a95814 to your computer and use it in GitHub Desktop.
Save shalk/8e6d5c30244b21a95814 to your computer and use it in GitHub Desktop.
perl 使用expect 模块, 问答都放在hash中,类似的修改问答和 命令就行了; perl use expect module ,all Question /Answer in Hash
#!/usr/bin/env perl
use 5.010;
use strict;
use Expect;
my $cmd = "perl simulate.pl";
my $timeout = 30;
my @question_list = qw/name age home/;
my $qa = {
"name" => "shalk\n",
"age" => "17\n",
"home" => "China\n",
};
my $exp = Expect->spawn($cmd) or die "can not spawn $cmd";
for my $ask (@question_list){
my $answer = $qa->{$ask};
$exp->expect($timeout,
[ qr/$ask/ => sub { my $exp = shift, $exp->send($answer) }, ],
);
}
$exp->soft_close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment