Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Attempting to open and pass info to MS Telnet

by giricredwolf (Acolyte)
on Aug 07, 2004 at 22:09 UTC ( #380954=perlquestion: print w/ replies, xml ) Need Help??
giricredwolf has asked for the wisdom of the Perl Monks concerning the following question:

First, please forgive a lack of technical terms. I'm very new to some of this.

I'm trying to write a perl program on WindowsXP that opens Telnet (telnet.exe) in a write-to mode. It then passes the phrase "set localecho" and an "enter" to set localecho on. Then it passes "open discworld.atuin.net" to open my favorite MUD. THen I want the program to exit while Telnet continues to run in another command prompt window.

Here's what I have so far:
use strict; #use strict... open(TELNET, "|telnet") or die "$!"; #open writable telnet or di +e sleep 5; #wait 5 seconds print TELNET "set localecho\n"; #Turn telnet "localecho" on sleep 5; #wait 5 seconds print TELNET "open discworld.atuin.net\n"; #Open DiscworldMUD
All I can find this does so far is that it opens Telnet. I'm not sure what I'm doing wrong or if I should use Win32::Process stuff. What I really want to do is change the default settings for TelNet, but I can't find a file that it pulls settings from. I'm just trying to find a way to get around typing in "set localecho" every time I run the thing.

Any help?

Comment on Attempting to open and pass info to MS Telnet
Download Code
Re: Attempting to open and pass info to MS Telnet
by saintmike (Vicar) on Aug 08, 2004 at 03:59 UTC
    I guess what you're intending is this: first establish the connection and then you'd like telnet to hand over control to you in interactive mode.

    The problem with your approach is that while you might be able to establish the session, you won't be able to jump into the open session interactively. At the end of your script, the session just gets dropped.

    If you can't find the file controlling telnet's default settings, I'd probably use Expect for this task . Expect lets you call telnet, waits for its prompt, then lets you send the set localecho command, wait for the prompt again and finally take over the session via Expect's interactive command.

    There's a Perl module (Expect) for it, but I'm not sure if it works on Windows. You might want to use the original, Tcl-(gack!)-based Expect version.

Re: Attempting to open and pass info to MS Telnet
by Jenda (Abbot) on Aug 08, 2004 at 23:46 UTC

    Have a look at the Win32::GuiTest module. You should be able to start telnet in a new console (system('start telnet');) and then send some keypresses to the console.

    You can install the module using PPM:

    c:\> ppm install Win32::GuiTest

    HTH, Jenda
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
       -- Rick Osborne

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://380954]
Approved by PERLscienceman
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2014-10-21 11:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (100 votes), past polls