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

Hey Monks, Originally I created a script that would execute multiple commands based on a scheduled time and to execute each command I used the line:
system("start $separate_command") and die $!,$?,$^E;
Using the system function, it would open up a new cmd window when executing each command. This way I could execute more than one command simultaneously. (Previously, it was using the cmd window that I was executing the script in to run each command, but this posed a problem, because after a command was executed, if it took 30 seconds, it skipped other scheduled commands that were scheduled within 30 seconds of the first command). Anyways, I currently am messing around with the Telnet module so I can execute commands on remote hosts, and my current code for executing a command with Telnet is this:
use Net::Telnet(); $commandExecution = new Net::Telnet(Host=>$location, + Dump_Log=>"debug.txt", + Prompt=>'/C:\\\\>.*$/'); $commandExecution->login($username,$password); $commandExecution->print($separate_command); $commandExecution->waitfor('/.+$/'); $commandExecution->close;
The above code runs telnet in the window the script is running. My question: Is there a way to have it run the telnet commands above, in a separate window, like it was doing when I was using the system() function?

Hope I was clear enough.

Thanks for your assistance.


Edge118 (Perl Noob)

Replies are listed 'Best First'.
Re: Using Net::Telnet Module on Windows machine
by BrowserUk (Patriarch) on Jul 08, 2004 at 15:15 UTC

    The simple mechanism would be to put your telnet code in to a small script that takes $separate_command as a command line argument.

    Then the main script uses

    system qq[ start perl SimpleTelnet.pl "$separate_command" ];

    for each client it needs to contact.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    "Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon
      Thanks for your response. It help me out alot.
      I have one more question: How do I pass more than 1 argument into the script? I tried a few things including the following, but it didn't work:
      system qq[start perl telnetExecution.pl "$separate_command","$location +"];
      Thanks again!

        Skip the comma between the arguments, they are delimited by whitespace. You only need the "s around them if they might contain spaces or tabs.

        If the arguments could contain quotes, things start getting messy if not impossible, so avoid that if you can.

        Running this may help clarify things.

        #! perl -slw use strict; my $command = q[ perl -le"print $_ for @ARGV; print 'Enter to exit'; < +STDIN>" ]; system qq[ start $command A B C "D E" F "G H I" ];

        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "Think for yourself!" - Abigail
        "Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon