| 
      
      
      From: <RGi...@a1...> - 2002-03-04 14:57:57
      
     | 
| > Here's what I'd like to do with Expect.pm:
> 
> * Spawn a telnet to somewhere.
> * Invoke a subshell
> *   From within that subshell, call another Perl program one or more
> times to interact with the telnet process spawned by the parent 
> process.
Let me try to summarize what I think you want to accomplish:
* connect to another machine via telnet/whatever
* have the user either
1) interact with the other machine
2) or start procedures/macros/scripts/whatever to do more complicated 
things on the other machine.
So what you effectively want to do is to impose yourself between the 
user and the remote connection.  Sounds like a job for interact
()/interconnect()...
> My first try was to write a short Perl program that spawned a telnet,
> did an expect to get to the prompt, then did 'system("bash");' to get
> into the subshell.  I then invoked program#2 which tried to interact
> with the telnet.  I used the pty that the spawned telnet was using
> as fd's 0,1 and 2 (found via lsof)  as the filename to re-open with
> exp_init(), but that didn't work.  It did sent the data to the pty,
> but it was received by the parent program rather than the spawned 
> telnet.I suspect I'probably running afoul of the pty master/slave 
> business,which I'm not very familiar with.
Ugh, that sounds twisted.  Why do you want to start another shell?  If 
you just want to ask the user what procedure/macro to start, why not do 
it yourself?  Use Readline and just give the user a prompt to enter 
something, then send that to the other machine or evaluate it 
yourself.  Or use interact() to have the user directly talk to the 
other machine.
If you want to write different perl subroutines for some tasks on the 
other machine, just get a string from the user and eval() it (there is 
no need to invent another language/write another parser, you already 
have perl at hand).  That way, the user can call predefined procedures 
from a library.
If you want to write scripts or programs in other languages to handle 
such tasks, have them set up to use stdin/out to communicate with the 
other machine, then spawn them with Expect and use interconnect() to 
get them talking to the spawned telnet connection.
I hope I presented some new ideas to get you started into the right 
direction.  Remember: KISS: Keep It Small and Simple!
Roland
--
RGi...@cp...
 |