以编程方式将Parameteres传递给交互式脚本

时间:2017-04-06 11:42:15

标签: perl perl-module perl-data-structures expect.pm

我们有一个交互式脚本(脚本1),它要求提供IP地址并继续执行它。脚本1是从script2调用的。  我们知道IP地址,我们希望自动将IP传递给脚本,以便不需要手动干预

我查看了Expect Module。但我无法在PRODUCTION服务器中安装该模块。

有人可以建议一种方法来解决这个问题。

1 个答案:

答案 0 :(得分:0)

试试这个,

#script2.pl

use strict;
use warnings;

use Getopt::Long;

GetOptions (
"ipAddress=s" => \$ip,
) or die("Enter IP address");

my $cmd = "perl script1.pl --ip=$ip";
system($cmd);

#script1.pl

use strict;
use warnings;

use Getopt::Long;
GetOptions (
"ip=s" => \$ip,
) or die("Enter IP address");

print "IP address is $ip";

执行这样的。

perl script2.pl --ipAddress=10.11.12.13

如果你想直接执行script1,可以这样执行,

perl script1.pl --ip=10.11.12.13
相关问题