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

Dear Monks, I am trying to write a very simple client application on Win.XP... it will use Net::Telnet to connect a GSM node and it will send a command to the GSM node again via telnet session...

Sometimes, after the command send, GSM node needs Ctrl-D to produce command output.

I have send command and capture output successfuly but I can not send Ctrl-D which is some commands require Ctrl-D.

How can I send Ctrl-D over Telnet session in Telnet cmd("") command ?

Could you please help me to solve this issue...it is very critical for my development... I am realy appricate all your help beforehand... with my Best Regards, bulent_sahin.
  • Comment on How can I send Ctrl-D over Telnet session

Replies are listed 'Best First'.
Re: How can I send Ctrl-D over Telnet session
by RMGir (Prior) on Sep 10, 2008 at 08:59 UTC
    ctrl-d is just the byte 0x04 (just like space, character 32, is the byte 0x20), so in perl, ^D is "\x4".

    So just put a "\x4" in your string where you want the ctrl-D, or even better:

    # also declare other ctrl chars you need... my $ctrlD = "\x4"; my $escape = "\x1b"; #... more code here... cmd("Send all the\ncommands you need\nincluding a ${ctrlD}");

    Mike

      Since asked for CTRL-D, I'd use "\cD" instead.

      - tye        

        That works... I didn't know that escape, thanks!

        Mike
      C:\>perl -e"print qq,\cD," ♦ C:\>perl -e"print qq,\cD," |hexdump 00000000: 04 - | | 00000001; C:\>perl -e"print qq,\cD," |od -tacx1 0000000 eot 004 04 0000001 C:\>
Re: How can I send Ctrl-D over Telnet session
by DrHyde (Prior) on Sep 10, 2008 at 10:41 UTC
    Send the ASCII EOT character, see this table for any others you might need.