gpt4 book ai didi

perl - 使用未初始化的值。我该如何解决这个错误?

转载 作者:行者123 更新时间:2023-12-02 14:12:03 25 4
gpt4 key购买 nike

#!/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 :

void send($string) - sends $string to the SSH server, returns nothing



因此, send显然不返回任何内容(void),这就是为什么您在尝试打印 send 的(不存在的)返回值时收到此警告的原因.如果要从服务器取回数据,请使用 peek , eat , read_all或类似的记录。

关于perl - 使用未初始化的值。我该如何解决这个错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45527914/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com