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

Hi Monks
Can I use the below code to vary the size of my spawned terminal if yes How. Thanks in advance.

This code is from the man page of Expect module.

How to propagate terminal sizes

my $exp = new Expect; $exp->slave->clone_winsize_from(\*STDIN); $exp->spawn("ssh somehost); $SIG{WINCH} = \&winch; sub winch { $exp->slave->clone_winsize_from(\*STDIN); kill WINCH => $exp->pid if $exp->pid; $SIG{WINCH} = \&winch; } $exp->interact();

20050625 Cleaned up by Corion: Added formatting

Replies are listed 'Best First'.
Re: Expect script doubt
by anonymized user 468275 (Curate) on Jun 27, 2005 at 09:10 UTC
    This "clone" sizing causes the size of the slave to be varied according to its master - Expect.pm offers no other flavours of window resizing. I can't find an o/s-independent module that has more specific terminal sizing. The call to ioctl is the way the Expect module changes the size of slave to master, but because the IO module has been split up into separate sections, none of which are specifically "Terminal" I haven't yet had time to dig deeper than that (IO::Handle was a disappointment from this specific respect) - but that's where I would look next.

    One world, one people

      Thank you for the response. May be if I explain you what I am trying to achieve here might help you to understand better my problem. I am executing a command in the spawned process(terminal), now when the command gets executed correctly then it gives output. Now if the output cannot be accomodated with in the current terminal size, it would display More... in the bottom of the output(like when we do ls | more). I will have to send the carriage return to the terminal through expect and get the complete output so that I can proceed. But my code is not working, it actually is breaking down before I send the carriage return to the terminal. I am seeing the output through a logfile ($exp_inst->log_file("$templog", "w");). Can you suggest if the code is fine and if yes then any other alternative to achieve this $exp_inst->expect($timeout, '-re' , $prompt, sub { my $fh = shift; $fh->send("$command\n"); } , timeout => sub { my_die "unable to get the prompt $prompt"; } ); sleep (2); $exp_inst->expect($timeout, qr'.*' , sub { $exp_inst->send("\n"); } , timeout => sub { print "Notting happening"; } );
        Any chance of putting the < code > < /code > tags round your code? I am afraid of missing something you put there otherwise.

        One world, one people