Проблемы с использованием Telnet в Perl? - PullRequest
1 голос
/ 04 августа 2011

У меня проблемы с отправкой команд и получением текста / данных из настроенного соединения telnet.

 #!perl
 #Telnet.pl

use Net::Telnet;

# Create a new instance of Net::Telnet, 
my $telnetCon = new Net::Telnet (Timeout => 20,
                                Dump_Log   => "dump.log",
                                Input_Log => "infile.log",
                                Output_log => "output.log",
                                Prompt => '/\$ $/') or die "Could not make connection.";

# Connect to the host of the users choice                                
$telnetCon->open('');

#get username and password from user
my $CXusername = '';
my $CXpassword = '';

my $task = '50104'; # Get this input from the search

# Recreate the login
# Wait for the login: message and then enter the username
$telnetCon->waitfor(match => '/login:/i');

# this method adds a \n to the end of the username, it mimics hitting the enter key after entering your username
$telnetCon->print($CXusername);

$telnetCon->waitfor(match => '/Password:/i');

# does the same as the previous command but for the password
$telnetCon->print($CXpassword);

#Wait for the login successful message
$telnetCon->waitfor(match => '/$/');

$telnetCon->cmd("viewtask 50104");
$telnetCon->cmd(" ");
$telnetCon->cmd(" ");

@output = $telnetCon->cmd("who");
print @output;

($output) = $telnetCon->waitfor(match => '/$/');

print "Output: ",$output;

if($searched =~ /MODIFIED files in Task $_[1] :(.*?)The/s){
    # to Logout of the telnet connection
    $telnetCon->print("exit");

    #return the modified data 
    return $1;
}

Скажите, если вопрос не имеет смысла, я постараюсь перефразировать его. First View Second View

Так что это вид telnet. Я застреваю на первом изображении при вводе $ telnetCon-> cmd ("viewtask 50140"). Я хочу перейти ко второму изображению и продолжить ввод команд в моем сеансе telnet.

1 Ответ

1 голос
/ 04 августа 2011

Метод Net::Telnet cmd записывает вашу команду (с добавлением \n) и ожидает приглашения. это несовместимо с ожиданием ввода вашей программы для завершения вывода.

Я думаю, что в вашем случае вы бы хотели использовать комбинацию print и getlines и / или waitfor, чтобы заставить это работать

...