#!/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()
使用そして、それはthe documentation of Net::SSH::Expectから、それを
'print($ stdout2)'(および他の数字)を使用するとどうなりますか?がんばろう。 – shellter
@shellterそれは私に同じエラーを与える – popeonhabbo123
あなたの質問に_solved_のようなコメントを編集しないでください。代わりに、あなた自身が適切な解決策であなたの質問に答えて、他の人に利益をもたらすことができます。 Stack Overflowはフォーラムではなく、QとAのサイトです。 – simbabque