i'm having some trouble with Net::Telnet. the remote machine queries the TERM shell variable in order to see if a 'resize' command should be issued. if TERM is 'no-resize-vt100', it does no resize, otherwise, 'resize' is executed. of course, 'resize' hangs on a non-interactive session, and the script gets no further. so, i try to set TERM via $ENV{TERM}, but it doesn't seem to work. in detail, here is the full script:
#!/usr/local/bin/perl use Env qw(TERM); $ENV{TERM} = 'no-resize-vt100'; use Net::Telnet; $connection = new Net::Telnet ( Host=>'ssd.jpl.nasa.gov', Port=>6775); $connection->open(); $connection->waitfor('/Horizons> /'); $connection->print('load vla-1'); $connection->waitfor('/Horizons> /'); $connection->print('page'); $connection->waitfor('/Horizons> /'); $connection->print('799'); $connection->waitfor('/.*Select.*: $/'); $connection->print('e'); $connection->waitfor('/.*Observe.*: $/'); $connection->print('o'); $connection->waitfor('/.*Coordinate.*: $/'); $connection->print('500@399'); $connection->waitfor('/.*Starting.*: $/'); $connection->print('1981-Mar-07 08:00'); $connection->waitfor('/.*Ending.*: $/'); $connection->print('1981-Mar-07 17:00'); $connection->waitfor('/.*interval.*: $/'); $connection->print('10m'); $connection->waitfor('/.*Accept.*: $/'); $connection->print('y'); $connection->waitfor('/.*Select.*: $/'); $connection->print('y'); $connection->print('q'); $connection->close; exit 0;
which hangs at the $connection->open() command, because the session tries to do a 'resize' (i can see this by putting in a $connection->input_log(...) statement). so, for some reason, the TERM variable doesn't seem to be getting set/reset correctly. the equivalent expect script, which looks like this:
#!/usr/bin/expect set env(TERM) no-resize-vt100 spawn telnet ssd.jpl.nasa.gov 6775 expect "Horizons> " { send "load vla-1\r" } expect "Horizons> " { send page\r } expect "Horizons> " { send 799\r } expect -re ".*Select.*: $" { send e\r } expect -re ".*Observe.*: $" { send o\r } expect -re ".*Coordinate.*: $" { send 500@399\r } expect -re ".*Starting.*: $" { send "1981-Mar-07 08:00\r" } expect -re ".*Ending.*: $" { send "1981-Mar-07 17:00\r" } expect -re ".*interval.*: $" { send 10m\r } expect -re ".*Accept.*: $" { send y\r } expect -re ".*Select.*: $" { send q\r } exit 0
works perfectly, i.e., the TERM variable seems to get set correctly, and the remote machine never attempts to do the 'resize'.

what am i doing wrong in the Perl version?

In reply to $ENV{TERM} and Net::Telnet by bbutler

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.