Jump to content

Display CMD console output in Autoit


 Share

Recommended Posts

I am trying to get text that is displayed in a command shell displayed in Autoit...How would I go about this..

Basically I am running a DOS application, that displays information in a DOS Shell, but I am wanting to display the outputted text in a Windows like GUI...

Any help would be greatly appreciated!

Cheers

Link to comment
Share on other sites

Have a look into new beta version for StdoutRead function.

$au3instpath = RegRead("HKLM\SOFTWARE\AutoIt v3\Autoit", "InstallDir")
$runPID = Run($au3instpath & "\Aut2Exe\upx.exe", "", @SW_HIDE, 2)
$ret = StdoutRead($runPID)
MsgBox (0, "STDOUT", $ret)
Link to comment
Share on other sites

Thanks for this pointed Lazycat, but where do I find this function? Am I wrong in saying it is not included in the latest version..

I am trying to capture the output from a DOS window into a GUI window...The only solution I can come up with at this point is to pipe the information out to a text file and create a loop that will keep on reading the file to update the GUI....Do you reckon this will work?

Thanks for you response thus far...and any more help would be greatly appreciated! :(

Link to comment
Share on other sites

The thread with link to the beta version is here.

Example. Runs a command and pipes the output to an edit box. GUI built using CyberSlug's AutoBuilder.

; Script generated by AutoBuilder 0.5 Prototype

#include <GuiConstants.au3>

;If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000

GuiCreate("STDIO Window", 425, 322,(@DesktopWidth-425)/2, (@DesktopHeight-362)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

; Create a read-only edit control
$eOutput = GuiCtrlCreateEdit("", 0, 10, 423, 260, BitOR($ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY))
; Exit button
$bExit = GuiCtrlCreateButton("Exit", 340, 285, 60, 20)

GuiSetState()
; Run child process and provide console i/o for it.
; Parameter of 2 = provide standard output 
$ourProcess = Run("ping autoitscript.com", @SystemDir, @SW_HIDE, 2)

; Loop and update the edit control unitl we hit EOF (and get an error)
While 1
   If $ourProcess Then
      ; Calling StdoutRead like this returns the characters waiting to be read
      $charsWaiting = StdoutRead($ourProcess, 0 , 1)
      If @error = -1 Then
         $ourProcess = 0
            MsgBox(0, "App Exited", "Process has exited...")
         ContinueLoop
      EndIf
      If $charsWaiting Then
         $currentRead = StdoutRead($ourProcess)
         GUICtrlSetData($eOutput, $currentRead, 1)
      EndIf
   EndIf
   $msg = GuiGetMsg()
   Select
      Case $msg = $GUI_EVENT_CLOSE
         ExitLoop
      Case $msg = $bExit
         ExitLoop
      Case Else
        ;;;
   EndSelect
WEnd
Exit

[Edit: Added a comment to explain the "peek" call to StdoutRead()]

Edited by DaveF

Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Link to comment
Share on other sites

Nice thank you but now how can I put this in my GUI? And link it to a button and have it go into a little window in my GUI? I will play with it but here is my GUI incase you fell like giving it a try. :(

#include <GuiConstants.au3>

; GUI
GuiCreate("Sample GUI", 400, 400)
GuiSetIcon(@SystemDir & "", 0)



; CONTEXT MENU
$contextMenu = GuiCtrlCreateContextMenu()
GuiCtrlCreateMenuItem("Context Menu", $contextMenu)
GuiCtrlCreateMenuItem("", $contextMenu);separator
GuiCtrlCreateMenuItem("&Properties", $contextMenu)

; INPUT MSG
GuiCtrlCreateLabel("IP", 230, 10, 200, 20)
; INPUT
GuiCtrlCreateInput("Sample Input Box",20,10, 200, 20)


; INPUT MSG
GuiCtrlCreateLabel("MSG", 230, 30, 200, 20)
; INPUT
GuiCtrlCreateInput("Sample Input Box",20,30, 200, 20)

; BUTTON MSG
GuiCtrlCreateLabel("Send IP A MSG", 86, 60, 200, 20)
; BUTTON
GuiCtrlCreateButton("SEND", 70, 75, 110, 20)


; EDIT
GuiCtrlCreateEdit(@CRLF & "all CMD feed back come's here", 10, 150, 377, 150)


; BUTTON MSG
GuiCtrlCreateLabel("View Your Network", 154, 350, 200, 20)
; BUTTON
GuiCtrlCreateButton("GO!!!", 147, 365, 110, 30)



; GUI MESSAGE LOOP
GuiSetState()
While GuiGetMsg() <> $GUI_EVENT_CLOSE
WEnd
Link to comment
Share on other sites

  • 6 months later...
  • 3 months later...

Very nice program DaveF. I have modified it to make a GUI dos window which uses STDIN as well.

; Script generated by AutoBuilder 0.5 Prototype
; Written by DaveF and Modified for STDIN by WFC

#include <GuiConstants.au3>
#include <Constants.au3>

;If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000
GuiCreate("STDIO Window", 425, 322,(@DesktopWidth-425)/2, (@DesktopHeight-362)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
Opt("GUIOnEventMode", 1)

; Create a read-only edit control
$eOutput = GuiCtrlCreateEdit("", 0, 10, 423, 260, BitOR( $ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY))
GUICtrlSetFont($eOutput, "8", 400, 0, "Lucida Console")
GUICtrlSetBkColor($eOutput, 0xFFFFFF)

; Exit button
$bExit = GuiCtrlCreateButton("Exit", 340, 295, 60, 20)
GUICtrlSetOnEvent($bExit, "Quit")
GUISetOnEvent($GUI_EVENT_CLOSE, "Quit")
; Create inbox
$inbox = GUICtrlCreateInput("", 0, 270, 423, 20)
GuiSetState()
ControlFocus ( "STDIO Window", "", $inbox )
; Run child process and provide console i/o for it.
; Parameter for STOUT and STDIN provide standard output and Standard input
$ourProcess = Run(@ComSpec & " /k cd " & @WorkingDir, @WorkingDir, @SW_HIDE, $STDOUT_CHILD + $STDIN_CHILD)
Dim $hoton = 0
; Loop and update the edit control unitl we hit EOF (and get an error)
While 1
    If $ourProcess Then
     ; Calling StdoutRead like this returns the characters waiting to be read
        $charsWaiting = StdoutRead($ourProcess, 0 , 1)
        If @error = -1 Then; Typing "exit" in the inbox will cause this error and exit the program
            MsgBox(0, "App Exited", "Process has exited...")
            Quit()
        EndIf
        If $charsWaiting Then
            $currentRead = StdoutRead($ourProcess)
            GUICtrlSetData($eOutput, $currentRead, 1)
        EndIf
    EndIf
    If WinActive("STDIO Window") Then 
    ; only set enter as a hotkey when window is active
    ; use $hoton as a toggle to prevent continually
    ; sending commands to the OS
        If Not $hoton Then HotKeySet("{enter}", "SendInp")
        $hoton = 1
    Else
        If $hoton Then HotKeySet("{enter}")
        $hoton = 0
    EndIf
WEnd

Func SendInp()
; Typing "enter" in the inbox branches here
; Read the inbox, add CR & line feed and write to StdIn
    StdinWrite($ourProcess, GUICtrlRead($inbox) & @CRLF)
    GUICtrlSetData($inbox, "")
EndFunc

Func Quit()
    Exit
EndFunc

WFC

Changed GUICtrlSetOnEvent($GUI_EVENT_CLOSE, "Quit") to GUISetOnEvent($GUI_EVENT_CLOSE, "Quit") so that clicking the "X" in the upper right corner of the GUI closes the GUI.

Made a few minor improvements. Changed hotkeyset so that the enter key is only set as a hotkey when the window is active. Changed background color in edit control to white and the font to Lucida Console which is a fixed pitch font. Now columns line up in a DIR command (for example).

Edited by WFC
Link to comment
Share on other sites

Very nice program DaveF. I have modified it to make a GUI dos window which uses STDIN as well.

WFC

I just started doing this :mellow:

Well you saved me from trouble, I figure I'll just personalise the gui :)

(The close button on top right corner doesn't work though, the program exits only when I hit the Exit button)

Edited by forger
Link to comment
Share on other sites

I just started doing this :mellow:

Well you saved me from trouble, I figure I'll just personalise the gui :)

(The close button on top right corner doesn't work though, the program exits only when I hit the Exit button)

Glad you found it of use. The close button didn't work for me either. Instead of GUICtrlSetOnEvent($GUI_EVENT_CLOSE, "Quit") change it to GUISetOnEvent($GUI_EVENT_CLOSE, "Quit"). I modified my code above to fix it.

WFC

Link to comment
Share on other sites

Cool, enjoy. :)

Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...