perl/expect I/O problems 
Author Message
 perl/expect I/O problems

I am using a perl script to feed input to an expect script, which when
send the line to a spawned shell, but I seem to have a problem getting
the data passed.  Here's the perl script (named kludge):

#!/usr/local/bin/perl

$EPATH = $ENV{"EPATH"} || die "set EPATH to your expect bin dir";

select STDERR; $| = 1;
select STDOUT; $| = 1;

$expect_pid = open (EXPECT, "| $EPATH/expect kludge.expect") || die;

while(1) {
    print EXPECT "echo foo\r";

Quote:
}

And here's the expect script (named kludge.expect):
#!/tstrel/mppsw/td_bin/expect

spawn /bin/csh
expect {% }

while (1) {
    expect_user {
        timeout { send_error "TIMEOUT on input\n"; exit 1 }
        eof { send_error "EOF on input\n"; exit 1 }
        -re .*\r
    }
    send $expect_out(buffer)
    expect {
        timeout { send_error "TIMEOUT!\n"; exit 1 }
        eof { send_error "EOF!\n"; exit 1 }
        {% }
    }

Quote:
}

Here's the first few lines of output:
kludge
spawn /bin/csh
% o foo
o: Command not found.
% echo foo
foo
echo foo
echo foo
echo foo
echo foo
{many more of the same deleted}
echo foo
eho: Command not found.

Some of the characters are getting dropped, it looks like.  What's
the problem?

Same results for both expect 5.2.0 and 3.22.11, using perl 4 PL34 on an
HP710 running HPUX 9.01.
--
Danny Faught -- Convex -- MPP OS Test Development
"Everything is deeply intertwingled."  (Ted Nelson, _Computer Lib_)



Wed, 19 Jun 1996 00:52:27 GMT  
 perl/expect I/O problems

Quote:
} I am using a perl script to feed input to an expect script, which when
} send the line to a spawned shell, but I seem to have a problem getting
} the data passed.  Here's the perl script (named kludge):

I've trimmed your scripts down to the bare essentials so it's easier
to see what's going on.

Quote:
} $expect_pid = open (EXPECT, "| $EPATH/expect kludge.expect") || die;
}
} while(1) {
}     print EXPECT "echo foo\r";
} }
} And here's the expect script (named kludge.expect):
}
} spawn /bin/csh
} expect {% }
}
} while (1) {
}     expect_user -re .*\r
}     send $expect_out(buffer)
}     expect "% "
} }
} Some of the characters are getting dropped, it looks like.  What's
} the problem?

My hypothesis is that you are overrunning the pty's input buffer.

Here's what is probably happening:
1) Perl script starts
2) Expect script starts
3) Perl writes an infinite string of "echo foo\recho foo\recho foo\r..."
   ("infinite" here means however many the OS let it write before it
    ran out of its time quantum or kernel buffer space.)
4) Your ".*\r" pattern matches much of the string,
5) Expect sent this HUGE string to csh's pty.
6) pty gags

Definition of "gag" is dependent upon your pty/tty driver and how
you've configured it.  Dropping characters is a common response.  A
limit of 256 characters is also common.  Obviously, you've exceeded
that.

This is not a bug in Perl or Expect (if you type *really* fast, you
can do it by hand) but in your script.  In the future, avoid infinite
strings :-)

Don



Wed, 19 Jun 1996 02:29:16 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Running Perl from one OS to another OS

2. expect in perl [Was expect: How to use interact]

3. Portability of Perl's Expect module: Having problems install

4. Problems to expect using Perl scripts with Win9x who were written with Linux

5. problem running Perl/Expect script suid

6. perl expect module problems

7. Perl and Expect problems?

8. Problems with OS/2 perl

9. Problems with IIS4, Perl and OS calls

10. 5.8.0 Perl compile problem on Mac OS 10.1.5

11. Problem moving OS/2-Perl, please help

12. Problems installing Perl for OS/2 (DOS)

 

 
Powered by phpBB® Forum Software