Change the net:telnet prompt durring runtime.

Discussion in 'Perl Misc' started by peter_de_groot_1966@yahoo.com, Mar 16, 2005.

  1. Guest

    Hi all,

    I have a problem with changing the telnet prompt durring runtime.
    My program has to connect to for me at the writing unknow unix machines
    with command prompts not know to me.
    To be able todo this I tought in updating the telnet prompt by reading
    a value from a file and then changing the prompt.

    My standard setting for the prompt is

    my $unix_cmd_prompt = '/[\$%#>:=]\s?$|term/i';

    I then add to the prompt with the sub
    add_system_prompt();

    sub add_system_prompt
    {
    my $customerprompt;
    my $promptfile = "custprompt.txt";
    if(-e $promptfile) {
    open(FH,"<$promptfile");
    while (defined ($customerprompt = <FH>)) {
    chomp $customerprompt;
    $customerprompt =~ s/^\s+//;
    if (length($customerprompt) gt 0) {
    $unix_cmd_prompt = $unix_cmd_prompt.'|'.$customerprompt;
    }
    }
    close(FH);
    }
    }

    and then set the prompt

    $t->prompt($unix_cmd_prompt);

    and offcourse I first devine the $t

    my $t = new Net::Telnet (
    Timeout => 240,
    Cmd_remove_mode => 0,
    Errmode => \&whinge,
    Output_record_separator => '',
    #Dump_log => 'dump.txt',
    );

    The login works fine until I add something to the prompt via the
    add_system_prompt adds something to the prompt.

    The documentation for net:telnet states that you have to single quote
    the regular expression.

    Is this where my problem is and if so what is the way around this
    , Mar 16, 2005
    #1
    1. Advertising

  2. Guest

    wrote:
    > Hi all,
    >
    > I have a problem with changing the telnet prompt durring runtime.
    > My program has to connect to for me at the writing unknow unix

    machines
    > with command prompts not know to me.
    > To be able todo this I tought in updating the telnet prompt by

    reading
    > a value from a file and then changing the prompt.
    >
    > My standard setting for the prompt is
    >
    > my $unix_cmd_prompt = '/[\$%#>:=]\s?$|term/i';
    >
    > I then add to the prompt with the sub
    > add_system_prompt();
    >
    > sub add_system_prompt
    > {
    > my $customerprompt;
    > my $promptfile = "custprompt.txt";
    > if(-e $promptfile) {
    > open(FH,"<$promptfile");
    > while (defined ($customerprompt = <FH>)) {
    > chomp $customerprompt;
    > $customerprompt =~ s/^\s+//;
    > if (length($customerprompt) gt 0) {
    > $unix_cmd_prompt = $unix_cmd_prompt.'|'.$customerprompt;
    > }
    > }
    > close(FH);
    > }
    > }
    >
    > and then set the prompt
    >
    > $t->prompt($unix_cmd_prompt);
    >
    > and offcourse I first devine the $t
    >
    > my $t = new Net::Telnet (
    > Timeout => 240,
    > Cmd_remove_mode => 0,
    > Errmode => \&whinge,
    > Output_record_separator => '',
    > #Dump_log => 'dump.txt',
    > );
    >
    > The login works fine until I add something to the prompt via the
    > add_system_prompt adds something to the prompt.
    >
    > The documentation for net:telnet states that you have to single quote
    > the regular expression.
    >
    > Is this where my problem is and if so what is the way around this



    The problem had nothing to do with the quotes.

    The orignal prompt ends on /i and my add routine added at the end of
    this which makes the regular expression worng.

    So in the new routine i fist delete /i then add the needed prompt(s)
    and add /i

    This now works
    , Mar 18, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pete Johansen

    NET::Telnet prompt regular expression

    Pete Johansen, May 5, 2004, in forum: Perl
    Replies:
    0
    Views:
    1,122
    Pete Johansen
    May 5, 2004
  2. Carcarius
    Replies:
    0
    Views:
    275
    Carcarius
    Dec 6, 2007
  3. Net::Telnet prompt problem

    , Apr 13, 2005, in forum: Perl Misc
    Replies:
    2
    Views:
    199
  4. Replies:
    0
    Views:
    75
  5. Replies:
    4
    Views:
    222
Loading...

Share This Page