in reply to Perl "expect" script, capturing output not working
for multiple lines you must also split all linesmy $ref = $exp->send("$cmd\n"); sleep(1); $ref = $exp->expect(TIMEOUT, [ $shell_prompts ] ); if (!$ref){ $log->warn("Timeout received!"); return -1; } $output = $exp->exp_before(); $output =~ s/^.*\r\n(.*)/$1/;
For debugging all characters in output string please use next code (decode all characters to ASCII):my @values = split(/\r\n/, $output); foreach my $val (@values) { print "$val\n"; }
sub ENCRYPT_DECRYPT() { my $Str_Message=$_[0]; my $Len_Str_Message=length($Str_Message); my $Str_Encrypted_Message=""; for (my $Position = 0;$Position<$Len_Str_Message;$Position++){ my $Key_To_Use = (($Len_Str_Message+$Position)+1); $Key_To_Use =(255+$Key_To_Use) % 255; my $Byte_To_Be_Encrypted = substr($Str_Message, $Position, 1) +; my $Ascii_Num_Byte_To_Encrypt = ord($Byte_To_Be_Encrypted); print "$Ascii_Num_Byte_To_Encrypt\n"; my $Xored_Byte = $Ascii_Num_Byte_To_Encrypt ^ $Key_To_Use; my $Encrypted_Byte = chr($Xored_Byte); $Str_Encrypted_Message .= $Encrypted_Byte; } return $Str_Encrypted_Message; } my $var=&ENCRYPT_DECRYPT($exp->exp_before());
|
|---|