From: <Sco...@we...> - 2011-02-22 00:00:24
|
Expect.pm Experts, I have been having the following problem, and was wondering if someone could provide a fix or workaround. When using the interact() function on Solaris 5.10 and Perl 5.8.4, everything I type is echoed back to the terminal 3 times (or 2 times too many). The extra echoes occur after I press the Enter key. Example script, exptest.pl use Expect; if ($ARGV[0] eq "-d") { $Expect::Log_Stdout=1; $Expect::Debug=3; $Expect::Exp_Internal=1; } my $process = Expect->spawn("cat > /dev/null") || die ("couldn't spawn: $!"); $process->interact(); When run from Solaris with the text "test\n", followed by Ctrl-D, I get the following: prompt> exptest.pl test test test ^D The command does not end when I type Ctrl-D. However, when I run the same script on Linux, I get the result I expect: prompt> exptest.pl test prompt> When I run with debugging, I can see that Expect is reading from the terminal the full text of what I typed, 2 extra times, and all from the same call to read(). prompt> exptest.pl -d Spawned 'cat > /dev/null' spawn id(3) Pid: 22103 Tty: /dev/pts/23 Expect::spawn('Expect', 'cat > /dev/null') called at ./exptest.pl line 12 Initialized handle id(4).' Initialized handle id(5).' Read handles: Read handle: 'spawn id(3)' Listen Handles: 'handle id(5)'. Read handle: 'handle id(4)' Listen Handles: 'spawn id(3)'. Setting handle id(4) to tty mode '-g' Setting tty for handle id(4) to 'raw -echo'. Setting handle id(4) to tty mode 'raw -echo' Attempting interconnection interconnect: read 1 byte(s) from handle id(4). Printed 't' to spawn id(3) from handle id(4). interconnect: read 1 byte(s) from spawn id(3). Printed 't' to handle id(5) from spawn id(3). tinterconnect: read 1 byte(s) from handle id(4). Printed 'e' to spawn id(3) from handle id(4). interconnect: read 1 byte(s) from spawn id(3). Printed 'e' to handle id(5) from spawn id(3). einterconnect: read 1 byte(s) from handle id(4). Printed 's' to spawn id(3) from handle id(4). interconnect: read 1 byte(s) from spawn id(3). Printed 's' to handle id(5) from spawn id(3). sinterconnect: read 1 byte(s) from handle id(4). Printed 't' to spawn id(3) from handle id(4). interconnect: read 1 byte(s) from spawn id(3). Printed 't' to handle id(5) from spawn id(3). tinterconnect: read 1 byte(s) from handle id(4). Printed '\r' to spawn id(3) from handle id(4). interconnect: read 17 byte(s) from spawn id(3). Printed '\r\ntest\r\r\ntest\r\r\r\n' to handle id(5) from spawn id(3). test test interconnect: read 1 byte(s) from handle id(4). Printed '\004' to spawn id(3) from handle id(4). interconnect: read 4 byte(s) from spawn id(3). Printed '^D\b\b' to handle id(5) from spawn id(3). ^D When I run from Linux, I get what I expect: prompt> exptest.pl -d Spawned 'cat > /dev/null' spawn id(3) Pid: 9836 Tty: /dev/pts/10 at HOMEDIR/perl/lib/perl5/site_perl/5.8.8/Expect.pm line 181 Expect::spawn('Expect', 'cat > /dev/null') called at ./exptest.pl line 12 Initialized handle id(4).' Initialized handle id(5).' Read handles: Read handle: 'spawn id(3)' Listen Handles: 'handle id(5)'. Read handle: 'handle id(4)' Listen Handles: 'spawn id(3)'. Setting handle id(4) to tty mode '-g' Setting tty for handle id(4) to 'raw -echo'. Setting handle id(4) to tty mode 'raw -echo' Attempting interconnection interconnect: read 1 byte(s) from handle id(4). Printed 't' to spawn id(3) from handle id(4). interconnect: read 1 byte(s) from spawn id(3). Printed 't' to handle id(5) from spawn id(3). tinterconnect: read 1 byte(s) from handle id(4). Printed 'e' to spawn id(3) from handle id(4). interconnect: read 1 byte(s) from spawn id(3). Printed 'e' to handle id(5) from spawn id(3). einterconnect: read 1 byte(s) from handle id(4). Printed 's' to spawn id(3) from handle id(4). interconnect: read 1 byte(s) from spawn id(3). Printed 's' to handle id(5) from spawn id(3). sinterconnect: read 1 byte(s) from handle id(4). Printed 't' to spawn id(3) from handle id(4). interconnect: read 1 byte(s) from spawn id(3). Printed 't' to handle id(5) from spawn id(3). tinterconnect: read 1 byte(s) from handle id(4). Printed '\r' to spawn id(3) from handle id(4). interconnect: read 2 byte(s) from spawn id(3). Printed '\r\n' to handle id(5) from spawn id(3). interconnect: read 1 byte(s) from handle id(4). Printed '\004' to spawn id(3) from handle id(4). interconnect: read 0 byte(s) from spawn id(3). Got EOF reading spawn id(3) Setting handle id(4) to tty mode '191:1280:15:35387:5:15:3:28:127:21:4:0:1:17:19:26:0' Closing handle id(4). at HOMEDIR/perl/lib/perl5/site_perl/5.8.8/Expect.pm line 1431 Expect::hard_close('Expect=GLOB(0x199a7610)') called at HOMEDIR/perl/lib/perl5/site_perl/5.8.8/Expect.pm line 1621 Expect::DESTROY('Expect=GLOB(0x199a7610)') called at ./exptest.pl line 13 eval {...} called at ./exptest.pl line 13 Expect::interact('Expect=GLOB(0x19894060)') called at ./exptest.pl line 13 handle id(4) closed. Closing spawn id(3). at HOMEDIR/perl/lib/perl5/site_perl/5.8.8/Expect.pm line 1431 Expect::hard_close('Expect=GLOB(0x19894060)') called at HOMEDIR/perl/lib/perl5/site_perl/5.8.8/Expect.pm line 1621 Expect::DESTROY('Expect=GLOB(0x19894060)') called at ./exptest.pl line 0 eval {...} called at ./exptest.pl line 0 spawn id(3) closed. Pid 9836 of spawn id(3) terminated, Status: 0xFFFFFFFFFFFFFFFF Closing handle id(5). at HOMEDIR/perl/lib/perl5/site_perl/5.8.8/Expect.pm line 1431 Expect::hard_close('Expect=GLOB(0x1959fb20)') called at HOMEDIR/perl/lib/perl5/site_perl/5.8.8/Expect.pm line 1621 Expect::DESTROY('Expect=GLOB(0x1959fb20)') called at ./exptest.pl line 0 eval {...} called at ./exptest.pl line 0 handle id(5) closed. prompt> I can see that after the Enter key is pressed, on Solaris I get: interconnect: read 17 byte(s) from spawn id(3). Printed '\r\ntest\r\r\ntest\r\r\r\n' to handle id(5) from spawn id(3). >From Linux: interconnect: read 2 byte(s) from spawn id(3). Printed '\r\n' to handle id(5) from spawn id(3). Something seems to be storing the keys I press in some sort of buffer, and then when the Enter key is pressed, it sends the entire line back onto the terminal for Expect to read. On Linux it is sending only the \r\n sequence. Does anyone know of any way to prevent this? I want the Solaris script to have the same behavior I am seeing on Linux. That is, I want the keys I type to be echoed, but only once. Is there a way to do this? Thanks, Scott |