|
From: Hal V. <ha...@th...> - 2002-03-02 14:36:42
|
I spent last week developing a program that does almost the same thing and
this week I've been successfully testing and using it online with another
system.
If you're going through the modem, or another device, you can open it like a
file (open DEVICE, "+>/dev/modem/"). There are a few other commands to use
to handle IO. I can't remember them, but if you look at the MODEMINIT
example in the tutorial, included with the Expect module, you will see all
you need for initializing the connection with the modem and for closing it.
This method, which I am using quite successfully (with only 1 problem, which
I'll mention in a bit), lets you easily dial in and communicate with another
computer using only perl, no telnet, no other programs at all. I love it,
since I was previously using TCL and the Expect that was developed using TCL.
That system controlled Minicom, which worked well, but I found TCL a pain to
program in, and, although I like Minicom, I feel much more comfortable using
only perl, instead of TCL, Expect, and Minicom. Fewer programs means less to
go wrong.
You send any commands to the modem (or whatever device you want to open) this
way, which gives you full control. If you're using any capture files, you
may get many more escape and control codes in the capture than you're used
to, but they can be purged with a simple filter subroutine (or awk, if you
want).
There are examples in the tutorial files that also use telnet (I think). If,
for some reason, you don't have the tutorial files, you can download the
lastest archive from CPAN, and they're in there. If that doesn't work, I'll
be glad to send them to you.
The only problem I'm having with this setup is when I try to capture
screenfuls of ino. The program I'm communicating with prints a screen of
info, then I type in a new ID number, and it prints a new screen of info. I
use Expect to detect when each screen is finished displaying. After the last
screen, I terminate a loop, then close the log file. I've found if I don't
display the last screen again, and use Expect to wait for the display to
complete again, the last screen is never caught in the capture file. In this
case the last screen is displayed twice to get it once. It seems like the
input for the last "expect" command is tossed and never makes it to the log
file. This can be worked around, so it isn't a huge problem, but I've
noticed it, so I thought a heads-up was appropriate.
Hal
On Saturday 02 March 2002 12:40 am, you 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?
>
> Thanks,
> -- Ed
>
> _______________________________________________
> Expectperl-discuss mailing list
> Exp...@li...
> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss
|