xeroTechnologiesLLC Posted February 11, 2012 Share Posted February 11, 2012 (edited) I'm writting a script to send data through a telnet session to a server and run a general summary and output it to a text file then close the telnet and CMD window. How can I code autoIT to say, if the command window string = "----more----" send the spacebar key, else continue on with the rest of the program? I'm still pretty new to autoIT and cycling through the wiki and such, but not sure what syntax to be looking for. Some sort of read screen? Thanks for any direction given. -nick Edited April 7, 2012 by xeroTechnologiesLLC Link to comment Share on other sites More sharing options...
xeroTechnologiesLLC Posted February 11, 2012 Author Share Posted February 11, 2012 currently reviewing the above forum post for further information and will reply back shortly. Link to comment Share on other sites More sharing options...
xeroTechnologiesLLC Posted February 11, 2012 Author Share Posted February 11, 2012 so what was being done there doesn't work on my end at all so... back to square 1. even using run(telnet, etc) doesn't seem to do what i need it to.... Link to comment Share on other sites More sharing options...
xeroTechnologiesLLC Posted February 11, 2012 Author Share Posted February 11, 2012 I have a gui calling a run("Cmd") and then sending a list of commands to it. Unfortunately it's randomly opening a 2nd cmd window and then running various keystrokes on the primary gui the called the cmd window. i have no idea why this is happening LOL Any other ideas? Link to comment Share on other sites More sharing options...
xeroTechnologiesLLC Posted February 11, 2012 Author Share Posted February 11, 2012 #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 237, 130, 192, 114) $Button1 = GUICtrlCreateButton("Run", 72, 56, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit case $Button1 run("CMD") Send(" telnet " & "###.###.###.###" & " -f" & " c:Output.txt" & @CR & "username" & @CR & "password" & @CR & "sum" & "{SPACE}" & "{SPACE}" & "{SPACE}" & "{SPACE}" & "{SPACE}" & "{SPACE}" & @CR & "exit" & @CR & "exit") EndSwitch WEnd Exit This little gem runs through quite a bit in the first cmd window, then stops and closes that then runs another on top of it that errors, then runs another that goes about 99% the way through and errors but it all writes to the text file... lol It seems amazingly buggy for something so simple - imo, but i'm not sure what i'm doing wrong. I have tried splitting the commands up into a line by line send - that gets even worse, opening multiple instances of the cmd window. Link to comment Share on other sites More sharing options...
xeroTechnologiesLLC Posted February 12, 2012 Author Share Posted February 12, 2012 Now I'm lost... local $cmd = run(@ComSpec & " telnet " & $IPAddressExtracted & " -f C:output.txt") Send("hi") As I understand this code - it should open a command prompt, telnet to the ip address and then type in the word 'hi' and output it all to a text file. But when the code hits the Send line - the focus goes back to my program and tries to send the keys there...why? I've been working on this for a few days and all I want to do is send a few keys to the CMD prompt. I tried to create a TCP session to the CMTS server I'm trying to connect to but it wouldn't take the variable as input for the IP address. I'm running out of routes to follow and would appreciate any help available. Thanks in advance, Nick. Link to comment Share on other sites More sharing options...
xeroTechnologiesLLC Posted February 12, 2012 Author Share Posted February 12, 2012 (edited) I decided to create a second script that was just telnetting to our CMTS, doing a login macro and running a basic command and exiting. Oddly, standalone, that worked. When I copied and pasted it back into my program's function - it worked. Not much was different other than the /k trigger. Below is the code. I'm still working on the IF statements as they do not currently work. expandcollapse popupfunc telnetOut($IPAddressExtracted, $upstreamExtracted, $upstreamShortExtracted) ;~ MsgBox(0, "", $IPAddressExtracted) local $cmd = run(@ComSpec & " /k ") WinActivate($cmd) Sleep(100) Send("telnet " & $IPAddressExtracted & " -f c:outTest.txt" & @CR, 1) Sleep(100) Send("nicholas.willcox" & @CR) Sleep(100) send("re11P3r_100" & @CR) Sleep(100) send("show cable modem c" & $upstreamExtracted & " | exc online" & @CR, 1) Sleep(100) send(" ") send(" ") send(" ") send(" ") send(" ") send(" ") send(" ") send(" ") send(@CR) If GUICtrlGetState($CMTSsumtotal) = $GUI_CHECKED Then Send("scmt" & @CR) send(" ") send(" ") send(" ") send(" ") send(" ") send(" ") send(" ") send(" ") send(" ") send(" ") send(" ") send(@CR) EndIf If guictrlgetstate($CMTSintsum) = $GUI_CHECKED Then send("show int sum" & @CR) send(" ") send(" ") send(" ") send(" ") send(" ") send(" ") send(" ") send(@CR) EndIf If GUICtrlGetState($CMTSsnr) = $GUI_CHECKED Then send("show controllers c" & $upstreamExtracted & " | inc snr" & @CR) send(@cr) EndIf send(@CR) send(@CR) Send(" exit" & @CR) Sleep(1000) Send("e") Sleep(1000) Send(" exit" & @CR) EndFunc edit: addition I opt for this route mainly because when I tried TCP functions - it would not connect to the cmts and would always say the ip or port was wrong - which the ip was a variable, shown above, and the port was always 23 - which is a basic telnet session that I know already connects just fine standalone. If anyone has any thoughts on why it would not work - I'm open for information. Edited February 12, 2012 by xeroTechnologiesLLC Link to comment Share on other sites More sharing options...
Shaggi Posted February 12, 2012 Share Posted February 12, 2012 (edited) If you're trying to run commands in cmd's, you should really write to standard streams. heres a basic example: $Pid = Run("<your program>",@WorkingDir, @sw_hide,0x1) ; pipe stdin Stdinwrite($pid,"<your command>" & @LF) ; linefeed works like enter on a normal prompt. Here's an example running a dir command: $Pid = Run("cmd.exe",@WorkingDir, @sw_hide,0x1) ; pipe stdin Stdinwrite($pid,"dir" & @LF) ; linefeed works like enter on a normal prompt. Edited February 12, 2012 by Shaggi Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG Link to comment Share on other sites More sharing options...
xeroTechnologiesLLC Posted February 15, 2012 Author Share Posted February 15, 2012 Thanks, I will check into this further and give it a test today! I really appreciate the time taken to provide the information. Link to comment Share on other sites More sharing options...
xeroTechnologiesLLC Posted February 15, 2012 Author Share Posted February 15, 2012 Works good up to the point I need to telnet to the CMTS But still useful. I will be continuing working on this through the week to find a work around for now. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now