Naveen_Naveen Posted May 23, 2017 Share Posted May 23, 2017 Hi Guys... I am new to autoit and i am facing a problem now. Any help would be appreciated. I am sending some commands to the cmd prompt and i need to execute a part of the code based on the result of the command i had sent earlier. Is this somehow possible in autoit. ? Here s a basic example of how i want it to behave $DOS= Send('washington' & ' ' & $aArray[0][1] ) Sleep(500) Send("{Enter}") Sleep(750) While 1 Sleep(10) $Message = StdoutRead($DOS) If @error then MsgBox($MB_SYSTEMMODAL, "Stdout Read:", "Washington already arrived") Exit 0 Else Send('Texas') Sleep(1000) Send("{Enter}") MsgBox(0,"!!!! SUCCESS !!!!","Everyone has arrived!") EndIf WEnd This is just a part of a code. and since i have a lot of servers, I am refraining from typing the servers in (fear of the recent ransomware virus) . So. The thing is, once i send the first command and press enter, i usually get a msg. and based on the msg, i want to either cancel the run or go further with the execution. I am still at loggerheads with myself... and the HELP did not help much.. any suggestions would be more than welcome.. am relying on the power of autoit forums now... Link to comment Share on other sites More sharing options...
Naveen_Naveen Posted May 23, 2017 Author Share Posted May 23, 2017 Hi Guys... I am new to autoit and i am facing a problem now. Any help would be appreciated. I am sending some commands to the cmd prompt and i need to execute a part of the code based on the result of the command i had sent earlier. Is this somehow possible in autoit. ? Here s a basic example of how i want it to behave $DOS= Send('washington' & ' ' & $aArray[0][1] ) Sleep(500) Send("{Enter}") Sleep(750) While 1 Sleep(10) $Message = StdoutRead($DOS) If @error then MsgBox($MB_SYSTEMMODAL, "Stdout Read:", "Washington already arrived") Exit 0 Else Send('Texas') Sleep(1000) Send("{Enter}") MsgBox(0,"!!!! SUCCESS !!!!","Everyone has arrived!") EndIf WEnd This is just a part of a code. and since i have a lot of servers, I am refraining from typing the servers in (fear of the recent ransomware virus) . So. The thing is, once i send the first command and press enter, i usually get a msg. and based on the msg, i want to either cancel the run or go further with the execution. I am still at loggerheads with myself... and the HELP did not help much.. any suggestions would be more than welcome.. am relying on the power of autoit forums now... Link to comment Share on other sites More sharing options...
Naveen_Naveen Posted May 23, 2017 Author Share Posted May 23, 2017 . Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 23, 2017 Moderators Share Posted May 23, 2017 Naveen_Naveen, Welcome to the AutoIt forums. But just the one thread at a time please. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Naveen_Naveen Posted May 23, 2017 Author Share Posted May 23, 2017 Oh.. i didnt realise that I had posted it twice.. Am really sorry.. and thanks for the welcome. !! Link to comment Share on other sites More sharing options...
Skysnake Posted May 24, 2017 Share Posted May 24, 2017 @Naveen_Naveen, welcome The trick is to read that STDOUT in a loop, not just once off. A quick work around is to dump the STDOUT to a txt file like this dir > myoutfile.txt Then read that out file with AutoIt. Skysnake Skysnake Why is the snake in the sky? Link to comment Share on other sites More sharing options...
Naveen_Naveen Posted May 24, 2017 Author Share Posted May 24, 2017 I am sorry... could you post a small description.. I am just starting with Autoit. ! and i dont fully get the hang of what you just said ! Link to comment Share on other sites More sharing options...
Triblade Posted May 24, 2017 Share Posted May 24, 2017 (edited) GaryFrost once helped me with this in my script. Please do note that the script I link to is from 2007 and not updated anymore. I think most would still work though, From this you should be able to extract the bits you need. Especially this bit: " Local $hping = Run(@ComSpec & " /c ping -n 1 -w 10 " & $sLocation, @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 $line = StdoutRead($hping) If @error Then ExitLoop $sData &= $line WEnd " The 'Local' line replaces your '$DOS =SEND' line. The While 1 loop reads all output and stitches them together in the $sData variable. Now you should be able to extract the output you seek with StringInStr, StringMid etc. Edit: oh, and don't forget to replace the ping command/parameters with the command you want. Good luck, Regards, Tri. Edited May 24, 2017 by Triblade My active project(s): A-maze-ing generator (generates a maze) My archived project(s): Pong3 (Multi-pinger) Link to comment Share on other sites More sharing options...
Naveen_Naveen Posted May 26, 2017 Author Share Posted May 26, 2017 Hi guys.. Thanks a lot for your help.. I found a workaround and implemented it. I accessed the telnet log and read the output for the telnet session from there and used that as a reference to validate my code. Thanks a lot for your time and help. Hoping to come back with more and more questions and learn in the process. Regards, NaveeN 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