-2
#!/usr/bin/expect -f 
spawn telnet 10.123.9.111 
expect login {send username\r} 
expect password {send password\r} 
----Here i want to execute commands----
----Commands are stored in an array in example.pl script----
----All variables are global in perl script----
----After executing these commands, control should again transfer to the called perl script----

我怎样才能做到?这是正确的方法吗?或者有什么更好的方法来做到这一点?

4

1 回答 1

0

您需要从 Perl 驱动控制。我会从 Perl 动态编写期望脚本,在命令中编码以从数组运行。然后 Perl 可以执行期望脚本:

system "expect", "/tmp/newly_written_script.exp";

并在期望返回时继续处理。

于 2012-08-13T16:41:15.337 回答