Folks-

The following code seems to work between Sun_SSH_1.1.1 boxes. I don't know why it works, but it does. The secret ingredient was to add a system call that sent something to STDOUT before the system call (or exec) that does the ssh.

I'm guessing a bug in sshd on the target host. Any thoughts?

Thanks

-Craig

use strict; use warnings; use IO::Select; my $cmd = '"cat /etc/passwd"'; my $login = 'usr@host'; my $pkey = "$ENV{HOME}/.ssh/privateKey"; my @shell = ( '/usr/bin/ksh' => ( -c => "$cmd", )); my @sshcmd = ('/usr/bin/ssh' => ( -t => (), -i => $pkey, -o => 'StrictHostKeyChecking no', $login, @shell, )); if(my $child = open (IFILE, '-|')) { print STDERR "I'm the parent\n"; print STDERR "Child pid=$child\n"; }else{ select(STDIN); $|++; select(STDOUT); $|++; select(STDERR); $|++; print STDERR "I am the child\n"; print "LINE 1...\n"; print "LINE 2...\n"; print "LINE 3...\n"; print "LINE 4...\n"; my $ret; $ret = system('echo hi'); print STDERR "CHILD 1: ret=$ret\n"; $ret = system(@sshcmd); print STDERR "CHILD 2: ret=$ret\n"; print "LINE 5...\n"; print "LINE 6...\n"; print "LINE 7...\n"; print "LINE 8...\n"; } my $select = IO::Select->new(); $select->add(\*IFILE); my @ready; while ( @ready = $select->can_read(5) ) { foreach my $fh (@ready) { my $line = <$fh>; print STDERR "line=$line"; if(eof($fh)) { $select->remove($fh); close($fh) || warn "Close problem on fh: $fh"; } } } close(IFILE);

In reply to Solution: Don't know why it works... by cmv
in thread IO::Select & ssh problem by cmv

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.