Can I abort telnet while it is still trying to connect?

12

3

At times I find myself telnetting from Windows XP to another server and that I state a wrong port number such as

c:\> telnet xxxxx.yy pp

After hitting Enter, I realize that I entered the wrong port number and would like to abort the telnet process with a ctrl-c, however, telnet doesn't seem to respond even to ctrl-c. So, I have to wait a few seconds until telnet returns with a

Connecting to xxxxx.yy... 
Could not open connection to the host, on port pp: Connect failed

It's rather annoying to wait for the error message, especially when I already know it will eventually come.

So, is there a way to immediately stop the telnet process?

René Nyffenegger

Posted 2009-11-14T10:34:04.237

Reputation: 1 862

right, good point. updated answer. – quack quixote – 2009-11-14T12:04:53.337

Answers

7

Edit: Of course, it's never that simple. As you've observed, Microsoft's telnet doesn't respond to ^] while waiting for a connection.

If you don't want to wait around, you only have two options:

  • Kill the telnet process (from another command shell or the task manager), or

  • Use another telnet client. PuTTY is a good choice, since it will launch as a separate window; even if you get the port wrong and the PuTTY window freezes, your command shell will be available to launch another instance with the correct port number.


Use the escape character (defaults to Ctrl+]). This brings up a telnet prompt at which you can close or quit the connection.

> telnet

Welcome to Microsoft Telnet Client

Escape Character is 'CTRL+]'

Microsoft Telnet> 

You can change this to nearly anything you like on your commandline by using the -e flag:

C:\>telnet /?

telnet [-a][-e escape char][-f log file][-l user][-t term][host [port]]
[...]
 -e      Escape character to enter telnet client prompt.
[...]

C:\>telnet -e '

Welcome to Microsoft Telnet Client

Escape Character is '''

Microsoft Telnet>

quack quixote

Posted 2009-11-14T10:34:04.237

Reputation: 37 382

The problem is: telnet doesn't respond to ctrl-] while it is in the process of connecting to the server. – René Nyffenegger – 2009-11-14T11:06:35.497

4which pretty much means it won't respond to anything. bad telnet client, bad. – quack quixote – 2009-11-14T12:06:49.527

Just curious: what escape-character did you try with the -e flag? A newline? A backspace? – Arjan – 2009-11-14T12:44:08.243

me? single-quote ('), exactly as shown. that output was captured from a winXP cmd.exe terminal. – quack quixote – 2009-11-14T16:01:16.180

Ahhh, I thought the single quote in telnet -e ' was the opening quote for something, like in telnet -e 'q'. Confused by the syntax highlighting I guess. :-) – Arjan – 2009-11-14T18:24:22.867

i actually tried something like that, but -e only expects a single character, so it doesn't bother with "is-this-a-string-or-not", just grabs the first character. i blame cmd.exe. – quack quixote – 2009-11-16T01:31:20.753

Just a little remark for CH-DE (swiss german) keyboards (maybe this is valid for all non-US keyboards?). In CH-DE keyboard the ] is on a alt-gr combination and CTRL+ALT-GR+] is not working, so you have to go with just CTRL+¨ (which is the key just left of Enter, which is the key that you have to press with alt-gr to get a "]" ) – raudi – 2013-06-25T10:00:10.627

let me rephrase: Just a little remark for CH-DE (swiss german) keyboards: Just Press CTRL+¨ (CTRL plus the Umlaut key) Maybe this is valid for all non-US keyboards? In CH-DE keyboard the ] is on ALT-GR+"¨" (th Umlaut Key, which is the key just left of Enter) combination. CTRL+ALT-GR+] is not working, so you have to go with just CTRL+"¨" and I'm not sure if for other layouts this would mean just CTRL plus the key left of ENTER or if it means CTRL plus the key that you have to press together wit alt-gr to get a "]" – raudi – 2013-06-25T10:06:34.593