我希望在运行安装脚本时自动输入密码。我在 Perl 中使用反引号调用了安装脚本。现在我的问题是如何使用输入密码expect
或者是其他东西?
my $op = `install.sh -f my_conf -p my_ip -s my_server`;
执行上述命令后,会打印密码行:
Enter password for the packagekey:
在上面的行中我想输入密码。
use 预计下午 https://metacpan.org/pod/Expect.
该模块专为需要用户反馈的应用程序控制而定制
#!/usr/bin/perl
use strict;
use warnings;
use Expect;
my $expect = Expect->new;
my $command = 'install.sh';
my @parameters = qw(-f my_conf -p my_ip -s my_server);
my $timeout = 200;
my $password = "W31C0m3";
$expect->raw_pty(1);
$expect->spawn($command, @parameters)
or die "Cannot spawn $command: $!\n";
$expect->expect($timeout,
[ qr/Enter password for the packagekey:/i, #/
sub {
my $self = shift;
$self->send("$password\n");
exp_continue;
}
]);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)