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

Normally system("/bin/echo \\\$stuff"); returns $stuff. this is true, after learning from a few mistakes (like \\$stuff) i felt as though i understood how to get a $ back from an object. alas this is not so. the Net::Telnet object does not seem to retrieve $'s. am i wrong in this? as i believe i have code to back me up on this one.
#!/usr/bin/perl -w use strict; use Net::Telnet; my $username = "user"; my $password = "password"; my $host = "localhost"; my $telnet = new Net::Telnet ('Timeout'=>'7', 'Prompt'=> '/.*([\$#\%>~]|\\\[\\e\[0m\\\ +] \[0m)\s?/' ); ; my $shiznat = "default value"; $telnet->open(Host=>$host); $telnet->login($username,$password); $telnet->dump_log("loging.log.log"); $telnet->cmd('String' => "/bin/echo \\\$stuff", 'Output' => \$shiznat); print $shiznat; $shiznat=$telnet->getline; print $shiznat; $telnet->cmd('String' => "/bin/echo \$stuff", 'Output' => \$shiznat); print $shiznat; $shiznat=$telnet->getline; print $shiznat;
this outputs
stuff stuff
anyone have any thoughts? (please note that getline will not solve the programs problem(just my curiousity) i am actually developing as i have to deal with a 6 line file (unless you can make it read all 6 (possibly 18) lines)) it appears (to me in my ignorance) that this should work correctly (well the 1st cmd the second is just to prove a point about $'s and how the escaping does not change the output) and if you check the log file you will discover that $stuff was echoed but only stuff returned to you for use
curious, no?
jcpunk

by the way thanks for all the help that was, is, and will be

Replies are listed 'Best First'.
Re: Net::Telnet, $, and crushed expectations
by castaway (Parson) on Jul 01, 2003 at 10:49 UTC
    You didn't say which client/host systems you tried this on, so I've just tried it running on an AIX, connecting to a HP-UX 11 machine (happened to have those handy). Using v5.6.1, and Net::Telnet 3.02, I get different results to you:

    jer@skiddaw: ~/perl > ./testelnet.perl $stuff jer@volvo: ~ read timed-out at ./testelnet.perl line 17 zsh: exit 255 ./testelnet.perl
    with the getlines in the code, and without them:
    jer@skiddaw: ~/perl > ./testelnet.perl $stuff jer@volvo: ~ $stuff jer@volvo: ~ jer@volvo: ~
    Same result Linux->HP-UX, I cant test ->Linux or ->AIX (one hasnt a telnet server, the other some weird login prompt ,)

    Which version of Net::Telnet are you using, possibly its an older/buggy one? My log and my results show that it can work, at least.

    C.

      i am currently testing Linux -> Solaris and the final program will likely run Solaris -> Solaris
      as for perl i am using 5.8.0 and i cannot determine my version of Net::Telnet.
      thanks for testing that code out, Solaris is probably being itself, foolish and annoyingly stupid
      jcpunk

      by the way thanks for all the help that was, is, and will be

Re: Net::Telnet, $, and crushed expectations
by Mr. Muskrat (Canon) on Jul 01, 2003 at 13:53 UTC

    Looks like a problem with your prompt pattern.

    Update: Or is it? Try changing from double quotes to single quotes in the lines you do the $telnet->cmds.
    i.e.: $telnet->cmd(String => '/bin/echo \\\$stuff',

      hmmmm, that is a thought, how so? my prompt is setup to match some of the possibles that are here, one of which ends in an ASCII sequence to stop the color change of their prompt. could this be what is screwing my program up?
      jcpunk

      by the way thanks for all the help that was, is, and will be