Hi , case 1: my $hostname = '10.10.2.45'; my $prompt1 = '/\>$/'; my $name = 'administrator'; my $password = 'nn'; my $string = 'net start '; my $session1 = Net::Telnet->new(Host => $hostname,) ; $session1->login(Name => $name, Password => $password, Prompt => $prompt1,); my @output = $session1->cmd(String => $string, Prompt => $prompt1,); print "Command output: @output\n"; # resultant output is stored line by line in @output array. case 2: my @before = $session1->waitfor('/successfully/'); print "before: @before\n"; $session1->close;
I am really new to perl. I am writing this code to telnet into windows machine and run dir/or any one command. If someone can help or give any ideas. The code works fine on the unix machine and runs the command 'ps -ef'. The code below has problem to recognize the C:\ prompt and gives time-out error. I have tried different combinations of the Regexp for the dos prompt but nothing seems to work. At certain expression it compiles but doesn't print. I tried the other way of using the "wait for" method (case2:)and use buffer. In that it is able to print what is in the buffer but not the exact output of the command. Say if you want to telnet to DOS machine and print the command 'dir' on that machine and see the output on your machine. Would appreciate if someone can help. thanks Nitin