Hallo Community
In einer GUI soll ein DOS-Befehlsablauf per StdoutRead dargestellt werden.
Dazu hab ich die "_getDOSOutput"-Function abgewandelt um jeweils den aktuellen Stand der DOS-Ausgabe abzufragen.
Beispiel mit ping:
Spoiler anzeigen
; AutoIt Version: 3.3.0.0
[/autoit] [autoit][/autoit] [autoit]Opt("WinWaitDelay", 500)
Opt("TrayIconHide", 0) ;0=show, 1=hide tray icon
Opt("MouseCoordMode", 0) ;1=absolute, 0=relative, 2=client
Opt("ExpandEnvStrings", 1) ;0=don't expand, 1=do expand
Opt("ExpandVarStrings", 1) ;0=don't expand, 1=do expand
Opt("WinDetectHiddenText", 0) ;0=don't detect, 1=do detect
Opt("WinTitleMatchMode", 1) ;1=start, 2=subStr, 3=exact, 4=advanced
Opt("WinTextMatchMode", 1) ;1=complete, 2=quick
#include <Process.au3>
#include <File.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$orange = "0xFF6600"
$green = "0x66FF33"
$yellow = "0xFFFF00"
$kin = "0xFF9966"
$turquoise = "0x00CCCC"
$magenta = "0xCC6699"
$lgreen = "0xCCFFCC"
$Form1 = GUICreate("CMD - GUI", 736, 748, 52, 44)
$Group1 = GUICtrlCreateGroup("", 16, 8, 697, 57)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("cmd", 16, 72, 337, 129)
$Label1 = GUICtrlCreateLabel("File", 32, 96, 60, 17)
$Input1 = GUICtrlCreateInput("", 104, 93, 233, 21)
GUICtrlSetData($Input1, "ping.exe")
$Label2 = GUICtrlCreateLabel("Count", 32, 136, 60, 17)
$Input2 = GUICtrlCreateInput("", 104, 133, 233, 21)
GUICtrlSetData($Input2, "19")
$Label3 = GUICtrlCreateLabel("Address", 32, 176, 60, 17)
$Input3 = GUICtrlCreateInput("", 104, 173, 233, 21)
GUICtrlSetData($Input3, "127.0.0.1")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("", 376, 72, 337, 129)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group4 = GUICtrlCreateGroup("", 16, 320, 697, 369)
$Button1 = GUICtrlCreateButton("START", 40, 704, 75, 25)
$Button2 = GUICtrlCreateButton("EXIT", 608, 704, 75, 25)
$Edit1 = GUICtrlCreateEdit("", 40, 344, 649, 329)
GUICtrlSetData(-1, "")
GuiCtrlSetBkColor(-1, $lgreen)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group5 = GUICtrlCreateGroup("", 16, 208, 697, 105)
$Label4 = GUICtrlCreateLabel("Command", 32, 232, 100, 17)
$Input4 = GUICtrlCreateInput("", 144, 229, 553, 21)
$Label5 = GUICtrlCreateLabel("", 32, 272, 100, 17)
$Input5 = GUICtrlCreateInput("", 144, 269, 553, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$show = GUISetState(@SW_SHOW) ; startet die GUI
Local $batch, $command,$winTitle
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
#cs
Case $Button1
GuiCtrlSetBkColor($Button1, $orange)
$command = GUICtrlRead($Input1) & " -n " & GUICtrlRead($Input2) & " " & GUICtrlRead($Input3)
GUICtrlSetData($Edit1,_getDOSOutput($command))
GuiCtrlSetBkColor($Button1, $green)
#ce
; #cs
Case $Button1
GuiCtrlSetBkColor($Button1, $orange)
$command = GUICtrlRead($Input1) & " -n " & GUICtrlRead($Input2) & " " & GUICtrlRead($Input3)
GUICtrlSetData($Input4, $command)
Local $text = ''
Local $Pid = Run(@ComSpec & ' /c ' & $command, '', @SW_HIDE, 2 + 4)
While 1
$text &= StdoutRead($Pid, False, False)
If @error Then ExitLoop
Sleep(500)
GUICtrlSetData($Edit1,$text)
WEnd
GuiCtrlSetBkColor($Button1, $green)
; #ce
Case $GUI_EVENT_CLOSE
Exit
Case $Button2
Exit
EndSwitch
WEnd
;#cs
Func _getDOSOutput($command)
Local $text = ''
Local $Pid = Run(@ComSpec & ' /c ' & $command, '', @SW_HIDE, 2 + 4)
While 1
$text &= StdoutRead($Pid, False, False)
If @error Then ExitLoop
Sleep(10)
WEnd
Return $text
EndFunc ;==>_getDOSOutput
;#ce
(Wenn man die Function "_getDOSOutput" selbst verwendet, wird erst nach beenden des Befehls die Ausgabe dargestellt.)
Leider scrollt in obigem Script das "EDIT-Feld" aber nicht von selbst.
Wie könnte man das Script erweitern um immer die neueste Ausgabezeile angezeigt zu bekommen ?
Gruß M.