in reply to Expect.pm early termination?

Just a heads up if anyone ever runs into this same issue. The problem ended up being in the Expect.pm module or more correct the IO::Tty module. The perl expect script I was running was talking to psh on the distant end and perl expect was sending a terminal window size of (0, 0) which libedit (which is used by psh) had a problem with. To solve this problem IO::Tty.pm has a function called clone_winsize_from() that allows you to set the terminal size yourself on the slave end. This ended up doing the trick:

$terminal->slave->clone_winsize_from(\*STDIN);
Adding this to any perl expect script that is having these same issues should do the trick. I have contacted the author of the Expect module and requested that he add explicit setting of the terminal window size in the "new" construct of the module. We shall see if this is in the next release.

Actually what I suggested he add to his module was the following code:

unless (eval{$self->clone_winsize_from(\*STDIN);}) { my $winsize = pack('SSSS', 25, 80, 0, 0); # rows, cols, #pixelsX, + #pixelsY ioctl($self->slave(), &IO::Tty::Constant::TIOCSWINSZ, $winsize); }
Since STDIN may not always be a tty and thus will fail a POSIX tty check in Tty.pm, I added a check for that and then explicitly set the terminal size using ioctl() manually if Tty.pm fails to do so.

This should cover both possibilities, but the portion that still allows Tty.pm to try and set it could be removed all together and just have Expect.pm explicitly set it itself every time. The above code (either method) can be added to your particular expect script too untill Expect.pm has this code. Just be sure to have the proper OO path for the function call (ie. $term->slave->clone_winsize_from(\*STDIN);).

Replies are listed 'Best First'.
Re^2: Expect.pm early termination?
by Anonymous Monk on Mar 10, 2017 at 04:48 UTC
    Hi, I face this same issue and thanks for yours solution. But I'm not sure where exactly to add those lines suggested by you in the expect.pm module. Can you kindly suggest me that?