cmv has asked for the wisdom of the Perl Monks concerning the following question:

Folks-

The attached program is driving me nuts! The idea here is to send the arguments for the ls command that the user selected (via checkbuttons), to the remote machine and display the resulting output.

The program (using the ARGS hash) fails in SSH with the error:
Tk::Error: input must be 8 bytes long at .../lib/site_perl/5.8.8/darwin/Crypt/DES.pm line 57.

If you comment out the ARGS line in hostls(), and uncomment the ARGS2 line, everything works fine.

Why? I can't figure this one out (grrrrr)...

Any help is appreciated!

Thanks

-Craig

Update: Added commented out help for windows users (same problem there too).

Update2: See Weird error with Cryprt::Blowfish and Crypt::DES for the person who did the real work, and Re: Strange Net::SSH::Perl and Tk Checkbutton Interaction!?! SOLVED!.

#!/usr/bin/perl require 5.004; use English; use strict; use Data::Dumper; use Tk; my %ARGS = ( l=>'-l', a=>'-a', s=>'-s'); my %ARGS2 = ( l=>'-l', a=>'-a', s=>'-s'); # Setup remote ssh connection... use Net::SSH::Perl; #use Net::SSH::W32Perl; # For windows my $host='remotehost'; my $ssh = Net::SSH::Perl->new($host) || die "Bad $host"; #my $ssh = Net::SSH::W32Perl->new($host) || die "Bad $host"; # For win +dows $ssh->login('remoteusr', 'remotepass') || die "Bad login"; # Create new window... my $top = MainWindow->new(-title=>'Options Test'); $top->minsize(470,225); my $f = $top->Frame()->pack; my $t = $top->Scrolled('Text')->pack; # Add checkbuttions in frame... for my $o (keys(%ARGS)) { $f->Checkbutton(-text=>$ARGS{$o}, -offvalue=>'', -onvalue=>$ARGS{$o}, -variable=>\$ARGS{$o}, -command=>\&hostls, )->pack(-side=>'left'); # Reset checkbutton variable (default is off)... $ARGS{$o}=''; } sub hostls { print STDERR Dumper(\%ARGS); my $args = join(' ', values(%ARGS)); # This fails #my $args = join(' ', values(%ARGS2)); # This works print STDERR "args=$args\n"; $t->delete('1.0', 'end'); my($stdout, $stderr, $exit) = $ssh->cmd("ls $args"); if($exit) { warn "Bad Command return\n$stderr"; return() }; $t->insert('end', $stdout); } MainLoop();

Replies are listed 'Best First'.
Re: Strange Net::SSH::Perl and Tk Checkbutton Interaction!?!
by zentara (Cardinal) on Nov 09, 2007 at 13:41 UTC
    Pretty weird. Maybe %ARGS is being internally used by Net::SSH::Perl? And it is confusing everything? Does %ARGS3 (or any other variant work?)

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
      zentara-

      Good thought! I was hoping that was it, but alas, it even fails when using $qqq:

      #!/usr/bin/perl use English; use strict; use Data::Dumper; use Tk; my $qqq = '-l'; my $www = '-l'; # Setup remote ssh connection... my $host='rhost'; use Net::SSH::Perl; #use Net::SSH::W32Perl; # For windows #my $ssh = Net::SSH::W32Perl->new($host) # For windows my $ssh = Net::SSH::Perl->new($host) || die "Bad $host"; $ssh->login('rusr', 'rpass') || die "Bad login"; # Create new window... my $top = MainWindow->new(-title=>'Options Test'); $top->minsize(470,225); my $f = $top->Frame()->pack; my $t = $top->Scrolled('Text')->pack; # Add checkbuttion in frame... $f->Checkbutton(-text=>$qqq, -offvalue=>'', -onvalue=>$qqq, -variable=>\$qqq, -command=>\&hostls, )->pack(-side=>'left'); # Reset checkbutton variable (default is off)... $qqq=''; sub hostls { print STDERR Dumper(\$qqq); print STDERR "qqq=$qqq\n"; $t->delete('1.0', 'end'); my($stdout, $stderr, $exit) = $ssh->cmd("ls $qqq"); # Fails #my($stdout, $stderr, $exit) = $ssh->cmd("ls $www"); # Works if($exit) { warn "Bad Command return\n$stderr"; return() }; $t->insert('end', $stdout); } MainLoop();
      This seems to be a really tough bug. Please help!

      Thanks

      -Craig

Re: Strange Net::SSH::Perl and Tk Checkbutton Interaction!?!
by Anonymous Monk on Nov 09, 2007 at 08:58 UTC
    try de/en coding your string?
Re: Strange Net::SSH::Perl and Tk Checkbutton Interaction!?!
by zentara (Cardinal) on Nov 09, 2007 at 17:17 UTC
    I see where the problem is, it's in the Checkbutton -variable option. If you comment out the -variable option it works.
    $f->Checkbutton( -text=>$qqq, -offvalue=>'', -onvalue=>$qqq, # -variable=>\$qqq, -command=>\&hostls, )->pack(-side=>'left');
    Checkbuttons can be tricky. They have a -variable and a -textvariable option. My guess is that with the -variable option you are converting $qqq to a number. $www is unaffected because you don't have it in the Checkbutton. I can't say for sure exactly how to handle it, because I get confused myself when I play with those Checkbuttons too deeply. If you read the perldoc for Tk::CheckButton, the variable option is used to specify a reference to a variable to set to indicate whether or not this button is selected. It is probably undef,1, or 0. Anyways that is where the problem lies.

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re: Strange Net::SSH::Perl and Tk Checkbutton Interaction!?! SOLVED!
by cmv (Chaplain) on Nov 09, 2007 at 18:27 UTC
    Folks-

    Why do I wait so long before google-ing my problem, and then (usually) find myself right back here at the PM site, finding the answer in an older node - Grrrrrr!

    This problem was solved in Weird error with Cryprt::Blowfish and Crypt::DES

    What happens here is that basically some code down the line (I don't know who or where yet, but I'm looking sternly at CheckButton) flipped the UTF-8 bit on this string (where is that, some internal flag that all Perl strings have?). This makes Crypt::DES and Crypt::Blowfish unhappy with the text they were asked to encrypt.

    To fix my particular test script, simply add this at the first line of hostls():

    use utf8; utf8::downgrade($qqq);
    Then, everything works fine. Many thanks to all who tried to help on this one! My grumpy-face is now gone.

    -Craig