Jump to content
Naveen_Naveen

Reading the CMD line output from DOS

Recommended Posts

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... :)

 

 

 

                                          

Share this post


Link to post
Share on other sites

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... :)

 

Share this post


Link to post
Share on other sites

Naveen_Naveen,

Welcome to the AutoIt forums.

But just the one thread at a time please.

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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 by Triblade

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...