EyeOpener has asked for the wisdom of the Perl Monks concerning the following question:

Hello world,

I'm trying to write a short script using Net::Telnet (first time with this module). I'm getting the hang of the various methods, but I've hit a snag.

My Unix account auto-launches an application (probably through .login or .profile). In an interactive telnet session, I break out of the application with Ctrl-\ (Control-Backslash) and continue working at a shell prompt. In my Perl script, I can't figure out how to break out of this app.

I've tried the break() method, but this doesn't work. My semi-educated guess is that this is sending a telnet break code, and not the Ctrl-\ the app or shell is looking for. I've also tried isolating the extended ASCII code for this key sequence and sending that via the print() method, but again no dice.

Any thoughts on how I can break out of this app? I'm not all that familiar with Unix, so I welcome all info on what might be happening in the background. Is the Ctrl-\ a standard "break" sequence, or is this app-specific? Is there a way to bypass the launching of this app on login?

If it matters, I'm developing this on ActiveState's Perl on a Win32 box, telnetting to a Unix host. In production, this script will be running on one Unix box, telnetting to another.

Thanks in advance!

Replies are listed 'Best First'.
(tye)Re: Sending key sequence with Net::Telnet
by tye (Sage) on Mar 14, 2002 at 16:50 UTC

    You don't show any code. I'd think that ->print("\x28") would work.

    I'd have used "\c\" to get CTRL-\ more directly but that is a syntax error because the parser code that looks for the closing " doesn't understand the \c\ escape. You can work around this with substr("\c\ ",0,1), but that seems like too much work.

    If you wonder what ->break() does, then why don't you just go look for yourself? BTW, it just boils down to $self->print("\xff\xf3").

            - tye (but my friends call me "Tye")
      Thanks for the reply, Tye!

      I'm making newbie errors all over the place here. As it turns out, the ->break() was working fine. I was misinterpreting what I saw in the input log file. I expected a nice human-readable log file based on the Net::Telnet docs, but instead it's filled with extended-ASCII or otherwise garbled text. I originally thought this was the output of the GUI-based app that's auto-launching, but I think instead this is a problem related to terminal character set or somesuch.

      The actual problem (the ->cmd timeout) was due to my setting the prompt incorrectly. I set it to the default /[%#>] $/, which would match what I see in an interactive telnet session. However, the log file shows that the server is sending something like "a21R39", which I again suspect is a terminal-type issue. For testing, I set the prompt to /./ and it continued past this point.

      BTW, your ->print("\x28") works for a break too. :-) Thanks again. I welcome anyone's thoughts on the prompt issue, but I won't be ticked if I'm ignored. I'll do a little more research before I post on this again.