#!/usr/bin/perl
use Net::SSH::Expect;
use warnings;
use strict;
#my($stdout, $stderr, $exit) = $ssh->cmd("ls -l /home/$usr")
# Making an ssh connection with user-password authentication
# 1) construct the object
my $ssh = Net::SSH::Expect->new (
host => "host",
password=> 'pwd',
user => 'user',
raw_pty => 1
#Expect=>log_file("finally.txt")
);
# 2) logon to the SSH server using those credentials.
# test the login output to make sure we had success
my $login_output = $ssh->login();
if ($login_output !~ /Welcome/) {
die "Login has failed. Login output was $login_output";
}
# disable terminal translations and echo on the SSH server
# executing on the server the stty command:
$ssh->exec("stty raw -echo");
my $stdout = $ssh->send(chr(13));
my $stdout2 = $ssh->send("SDT-FI");
my $stdout3 = $ssh->send("ENG");
my $stdout4 = $ssh->send('SORT FI-WIP "84144"');
my $stdout5 = $ssh->send(chr(13));
my $stdout6 = $ssh->send("OFF");
my $stdout7 = $ssh->send(chr(13));
print($stdout3);
#$expect->log_file("adp-n.txt");
#y $line;
# returns the next line, removing it from the input stream:
# while (defined ($line = $ssh->read_all())) {
# print $line . "\n";
#}
,所以我試圖打印$ stdout3這樣我就可以得到關於輸出 信息,但我一直「在connnn3.pl線50未初始化值$ stdout3在打印」越來越使用未初始化的值。我該如何解決這個錯誤?
是有什麼在我的代碼錯了? 我該如何解決這個問題?
更新,已解決! 爲什麼它返回「未初始化值的」的原因是因爲該功能
send()
是無效的,所以不是我用
exec()
這解決它
當你有'print($ stdout2)'(和其他數字)時會發生什麼?祝你好運。 – shellter
@shellter它給了我同樣的錯誤 – popeonhabbo123
請不要編輯評論像_solved_到你的問題。相反,用適當的解決方案自己回答你的問題,以便其他人可以受益。堆棧溢出不是論壇,而是Q和A站點。 – simbabque