littlebigman Posted March 23, 2023 Posted March 23, 2023 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 Jos Posted March 23, 2023 Developers Posted March 23, 2023 (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 March 23, 2023 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.
littlebigman Posted March 23, 2023 Author Posted March 23, 2023 (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)
Developers Jos Posted March 23, 2023 Developers Posted March 23, 2023 Not much we can do unless you have an replicator script so we can actually see what you are doing and test. 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.
littlebigman Posted March 23, 2023 Author Posted March 23, 2023 Voilà expandcollapse popup#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 Jos Posted March 23, 2023 Developers Posted March 23, 2023 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.
littlebigman Posted March 23, 2023 Author Posted March 23, 2023 It's "GNU Wget 1.21.1 built on mingw32." Maybe it's because there are two loops: The GUI msg loop, and the StdoutRead() loop within, preventing Windows/the app from updating the edit box?
Developers Solution Jos Posted March 23, 2023 Developers Solution Posted March 23, 2023 (edited) This works with the version I currently have: expandcollapse popup#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 March 23, 2023 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.
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