2011-11-27 52 views
1

我的代碼如下淨SSH預計打印輸出

use Net::SSH::Expect; 

my $ssh = Net::SSH::Expect->new (
      host => "$node_name", 
      user => 'admin', 
      timeout => 10, 
      raw_pty => 1, 
      ); 

$ssh->run_ssh() or die "SSH process couldn't start: $!"; 

$ssh->waitfor('password: '); 

$ssh->send("$password"); 

$ssh->waitfor('mml> '); 

@ls=$ssh->exec("$command"); 

print @ls; 

#BREAK1: At this point remote device ask for "Press Enter to continue..." because output is more than one page..that is why below code 

while ($ssh->waitfor('continue')) { 
$line=$ssh->send("\n"); 
print $line; 
} 

我想打印所有的輸出拍攝的,但它只能打印這是由@ls=$ssh->exec("$command");捕獲,它不打印這是由下面的代碼BREAK1捕獲任何東西。當輸出大模塊的

回答

0

的Perldoc reccomends如下:

# When running a command that causes a huge output, 
# lets get the output line by line: 
$ssh->send("find /"); # using send() instead of exec() 
my $line; 
# returns the next line, removing it from the input stream: 
while (defined ($line = $ssh->read_line())) { 
    print $line . "\n"; 
} 

還要注意,發送()是不應該返回任何東西,你應該使用read_line()或read_all()。 Module doc

+0

您好,我試過相同,它可以很好地用於第二頁只(基本上我有5-6頁輸出的)..它打印兩頁,但沒有打印第二頁以後的頁面....任何幫助? – Mahesh

+0

我認爲你可以嘗試檢查每一行'繼續',如果發現模式發送返回飼料在while循環內。另一種方法是在調用waitfor('continue')循環後使用before()函數。 –

+0

天啊!最後它完成了......做{sr-> send(「\ n」); $ line = $ ssh-> read_line(); push(@ls,「$ line」); } while($ line!〜/ mml> /); foreach(@ls){ print「$ _ \ n」; } – Mahesh

0

添加此$ssh->exec("stty raw -echo");

+0

請將您的代碼放在'代碼塊'的'代碼(內聯)'字符的幫助下。對於代碼段,在每行的文本前面添加4個空格。謝謝! – ibiza

+0

提供更多信息,告訴海報爲什麼你認爲這會解決他們的問題或他們做錯了什麼。 – SashaZd