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

Dear Perl Monks, I am writing you to seek enlightenment in the realm of Expect.pm

I have a written a perl expect script that runs as expected when I execute it from a terminal or shell.

However, if I execute it using backticks or the system command from a perl cgi script via browser, I receive the error in the subject line: Given filehandle is not a tty in clone_winsize_from. The file handle I am passing to clone_winsize_from is \*STDIN.

I have read online that it could be an issue with the corresponding profile's .bashrc file and it'd be appropriate to make some edits there, however, the default apache2 account that runs does not currently have a .bashrc nor .bash_profile file. It currently runs under www-data.

Has anybody come across something similar to this before? Apologies if I am asking a question that has already been answered.

Any assistance would be greatly appreciated.

code snippet:

use Expect;
my $exp = new Expect;
my $timeout = 30;
$exp->raw_pty(1);
$exp->slave->clone_winsize_from(\*STDIN);

  • Comment on Given filehandle is not a tty in clone_winsize_from

Replies are listed 'Best First'.
Re: Given filehandle is not a tty in clone_winsize_from
by aitap (Curate) on Aug 23, 2013 at 09:18 UTC
    The problem is that when a program is run under CGI, its STDIN is a pipe to the HTTP server process (where POST data can be read from), which is not a terminal. Looks like an XY Problem. What program do you run under Expect and how does it misbehave?
      Ah, thank you aitap.

      That made sense -- I have gone ahead and used the following code to solve my problem:

      my $winsize = pack('SSSS', 25, 80, 0, 0); # rows, cols, #pixelsX, #pixelsY ioctl($exp->slave(), &IO::Tty::Constant::TIOCSWINSZ, $winsize);



      As you had suggested, I am no longer referencing a terminal session that is unavailable to me, but instead, am creating one on the fly with the dimensions required. Thanks again for your helpful advice to lead me onto the right track. In the event that you feel there is a better solution please do let me know.