From: Austin S. <te...@of...> - 2002-03-02 07:52:38
|
On Sat, Mar 02, 2002 at 12:40:25AM -0500, Ed Ravin wrote: > 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. > > 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. > > Any idea how to get what I want to happen? Is it even possible? > It's possible, though it may not be what you want. You would do something along the lines of close STDIN and STDOUT, then reopen them with the filenumber of the tty, then exec() the program, e.g. bash. You can look at the code for spawn() to see how this is done to open the initial program. Also you will need to make sure you set raw mode on the pty, or you will have processes echoing at themselves. Another way is to have an expect script that does interact() at some point and uses named pipes as i/o. I think that's how things like kibitz work. Performance-wise it's less efficient, but probably easier to code. Thirdly, you could have the called perl program call the telnet expect process and work with it as if it were any other process. It's hard to tell (for me anyway) what you're trying to accomplish. Austin |