开发者

telnet inline with perl?

Is there a way to allow perl to initiate a telnet session and programmatically issue commands to that telnet session?

I initially tried a stupid method:

commands.pl:

sleep(1);
print $command1;
sleep(1);
print $command2;

and then

> perl commands.pl | telnet 开发者_开发知识库www.host.com port

This does not work.


There is a Net::Telnet module.

use Net::Telnet ();
$t = new Net::Telnet (Timeout => 10,
                      Prompt => '/bash\$ $/');
$t->open("sparky");
$t->login($username, $passwd);
@lines = $t->cmd("who");
print @lines;

(Example taken from that page.)


One option would be through Perl's interface to Expect.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜