我遇到了一些麻煩發送命令,並從我設置的telnet連接接收文本/數據。在perl中使用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;
}
告訴我,如果問題沒有意義,我會嘗試並對其進行改寫。
所以這是telnet視圖。當我輸入$ telnetCon-> cmd(「viewtask 50140」)時,我卡在第一張圖像上。我想到第二個圖像並繼續將命令輸入到我的telnet會話中。
我不知道如果我得到你的問題,'$ telnetCon-> CMD( 「」);'超時?是'viewtask'等待輸入,任何機會? – Hasturkun
嗯有點當我第一次進入viewtask ...它打印一些文件,然後等待另一個輸入來繼續顯示文件的其餘部分 – Shahab