Jump to content

Recommended Posts

Posted

Hello,

I'm only getting started learning how to launch CLI apps, so it could be something obvious, but I can't find how to display data returned from a command-line application while it's running, ie. as an alternative to showing the CMD window:

;How to read STDOUT while app is running?
;Local $iPID = RunWait($LINE, @WorkingDir, @SW_HIDE,$STDOUT_CHILD)
Local $iPID = Run($LINE, @WorkingDir, @SW_HIDE,$STDOUT_CHILD)
If @error Then
    MsgBox($MB_ICONERROR, "Error", "Download failed.")
Else
    ; Wait until the process has closed using the PID returned by Run.
    ProcessWaitClose($iPID)

    Local $sOutput = StdoutRead($iPID)
    GUICtrlSetData($Edit1, _ArrayDisplay($sOutput))
EndIf

Thank you.

  • Developers
Posted (edited)

What is the _ArrayDisplay() supposed to do in the update statement for the gui control? Have you tried without ?

Something like this maybe? (Untested)

;How to read STDOUT while app is running?
;Local $iPID = RunWait($LINE, @WorkingDir, @SW_HIDE,$STDOUT_CHILD)
Local $iPID = Run($LINE, @WorkingDir, @SW_HIDE,$STDOUT_CHILD)
If @error Then
    MsgBox($MB_ICONERROR, "Error", "Download failed.")
Else
    ; get output until the process is closed.
    While 1
        Local $sOutput = StdoutRead($iPID)
        if @error then ExitLoop
        GUICtrlSetData($Edit1, $sOutput)
        Sleep(100)
    WEnd
EndIf

 

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

(I replied to the wrong thread. Atmosphere…)

The editbox scrolls down, but nothing gets displayed, even after exiting the switch/case in the GUI loop

Local $iPID = Run($LINE, @WorkingDir, @SW_HIDE,$STDOUT_CHILD)
If @error Then
    MsgBox($MB_ICONERROR, "Error", "Download failed.")
Else
    ; get output until the process is closed.
    While True
        Local $sOutput = StdoutRead($iPID)
        if @error then ExitLoop
        GUICtrlSetData($Edit1, GUICtrlRead($Edit1) & @CRLF & $sOutput)
        Sleep(100)
    WEnd
EndIf
; Wait until the process has closed using the PID returned by Run.
ProcessWaitClose($iPID)
Posted

Voilà

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <Clipboard.au3>
#include <AutoItConstants.au3>
#include <Array.au3> ; Required for _ArrayDisplay only.

Const $URL = "Download"
Const $LINE = "c:\wget.exe -c " & ClipGet()
Const $OUTPUTDIR = "c:\tmp\"

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate($URL, 623, 449, 279, 114)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 601, 385)
GUICtrlSetState($Edit1, $GUI_DISABLE)
GUICtrlSetData($Edit1, ClipGet())
$OK = GUICtrlCreateButton("OK", 8, 408, 123, 33)
$Cancel = GUICtrlCreateButton("Cancel", 490, 405, 123, 33,$BS_DEFPUSHBUTTON)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While True
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $OK
            FileChangeDir ($OUTPUTDIR)
            ConsoleWrite($LINE & @CRLF)
            GUICtrlSetData($Edit1, $LINE & @CRLF)

            Local $iPID = Run($LINE, @WorkingDir, @SW_HIDE,$STDOUT_CHILD)
            If @error Then
                MsgBox($MB_ICONERROR, "Error", "Download failed.")
            Else
                ; get output until the process is closed.
                While True
                    Local $sOutput = StdoutRead($iPID)
                    if @error then ExitLoop
                    GUICtrlSetData($Edit1, GUICtrlRead($Edit1) & @CRLF & $sOutput)
                    Sleep(100)
                WEnd
            EndIf

            ; Wait until the process has closed using the PID returned by Run.
            ProcessWaitClose($iPID)

        Case $Cancel,$GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

 

  • Developers
Posted

Which wget are you using as this isn't a standard windows (10) command available? This to ensure we test with the proper version.
I assume any link to a downloadable file can be tested with?

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

  • Developers
  • Solution
Posted (edited)

This works with the version I currently have:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <Clipboard.au3>
#include <AutoItConstants.au3>
#include <Array.au3> ; Required for _ArrayDisplay only.

Const $URL = "url for filedownload"
Const $LINE = @comspec & ' /c "' & @ScriptDir & '\wget.exe" -c ' & $URL
Const $OUTPUTDIR = "d:\tmp\"

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate($URL, 623, 449, 279, 114)
$Edit1 = GUICtrlCreateEdit("", 8, 8, 601, 385)
;~ GUICtrlSetState($Edit1, $GUI_DISABLE)
GUICtrlSetData($Edit1, $URL)
$OK = GUICtrlCreateButton("OK", 8, 408, 123, 33)
$Cancel = GUICtrlCreateButton("Cancel", 490, 405, 123, 33,$BS_DEFPUSHBUTTON)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Local $sOutput
Local $sOuterr

While True
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $OK
            FileChangeDir ($OUTPUTDIR)
            ConsoleWrite($LINE & @CRLF)
            GUICtrlSetData($Edit1, $LINE & @CRLF)

            Local $iPID = Run($LINE, @WorkingDir, @SW_HIDE, $STDOUT_CHILD + $STDERR_CHILD )
            If @error Then
                MsgBox($MB_ICONERROR, "Error", "Download failed.")
            Else
                ; get output until the process is closed.
                While True
                    $sOutput = StdoutRead($iPID) & StderrRead($iPID)
                    if @error then ExitLoop
                    GUICtrlSetData($Edit1, $sOutput, "x")
                    Sleep(100)
                WEnd
            EndIf

            GUICtrlSetData($Edit1, @lf & "Done..", "x")

        Case $Cancel,$GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Try that and see what it does for you. :) 

Edited by Jos
Bit Cleaner code

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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
  • Recently Browsing   0 members

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