StdoutRead - Ausgabe automatisch scrollen

  • 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]

    ; 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

    [/autoit] [autoit][/autoit] [autoit]

    #include <Process.au3>
    #include <File.au3>
    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <ProgressConstants.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    $orange = "0xFF6600"
    $green = "0x66FF33"
    $yellow = "0xFFFF00"
    $kin = "0xFF9966"
    $turquoise = "0x00CCCC"
    $magenta = "0xCC6699"
    $lgreen = "0xCCFFCC"

    [/autoit] [autoit][/autoit] [autoit]

    $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

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ;#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

    [/autoit]


    (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. :huh:
    Wie könnte man das Script erweitern um immer die neueste Ausgabezeile angezeigt zu bekommen ?

    Gruß M.

    2 Mal editiert, zuletzt von Macrostop (29. April 2009 um 23:36)

  • Nachdem Du den aktuellen Text in das Edit-Feld geschrieben hast:

    [autoit]

    GUICtrlSetState($Edit1, $GUI_FOCUS) ; kann sein das diese Zeile nicht nötig ist, wenn gerade etwas hineingeschrieben wurde
    Send("{END}")

    [/autoit]

    Zur Nutzung dieses Forum's, ist ein Übersetzer für folgende Begriffe unerlässlich:

    "On-Bort, weier, verscheiden, schädliges, Butten steyling, näckstet, Parr, Porblem, scripe, Kompletenz, harken, manuel zu extramieren, geckukt, würglich, excell, acces oder Compilevorgeng"

  • Hallo Micha_he

    Vielen Dank für Deine Antwort, hat genau gepasst. :thumbup:

    [autoit]

    GUICtrlSetState($Edit1, $GUI_FOCUS)

    [/autoit]

    - muß drinstehen, sonst springt die Zeile nicht weiter.

    Danke und Gruß M.

  • Hallo Community

    Die Lösung funktioniert zwar, doch sobald man in das "EDIT-Feld" klickt ist es vorbei mit dem "Auto-Scroll".
    Das gilt auch wenn das "EDIT-Feld" disabled war.

    Verbesserte Version:

    Spoiler anzeigen
    [autoit]

    ; 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

    [/autoit] [autoit][/autoit] [autoit]

    #include <Process.au3>
    #include <File.au3>
    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <ProgressConstants.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    $orange = "0xFF6600"
    $green = "0x66FF33"
    $yellow = "0xFFFF00"
    $kin = "0xFF9966"
    $turquoise = "0x00CCCC"
    $magenta = "0xCC6699"
    $lgreen = "0xCCFFCC"

    [/autoit] [autoit][/autoit] [autoit]

    $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)
    ;GUICtrlSetState($Edit1, $GUI_DISABLE)
    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)
    GUICtrlSetState($Edit1, $GUI_FOCUS)
    Send("{END}")
    WEnd
    GuiCtrlSetBkColor($Button1, $green)
    ; #ce
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button2
    Exit
    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ;#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

    [/autoit]

    Wie könnte man diesen Umstand umgehen ?

    Gruß M.

  • nachdem in Deiner Version der Exit Button bei laufendem ping nicht abgefragt wird,
    hab ich mal versucht gleich beide Probleme zu lösen.

    Du kannst die AdlibEnable/AdlibDisable Funktion auch für andere Funktionsaufrufe verwenden.
    Halt immer nur einen zur gleichen Zeit...

    Spoiler anzeigen
    [autoit]

    ; 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

    [/autoit] [autoit][/autoit] [autoit]

    #include <Process.au3>
    #include <File.au3>
    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <ProgressConstants.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    $orange = "0xFF6600"
    $green = "0x66FF33"
    $yellow = "0xFFFF00"
    $kin = "0xFF9966"
    $turquoise = "0x00CCCC"
    $magenta = "0xCC6699"
    $lgreen = "0xCCFFCC"

    [/autoit] [autoit][/autoit] [autoit]

    $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)
    ;GUICtrlSetState($Edit1, $GUI_DISABLE)
    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
    Case $Button1
    GuiCtrlSetBkColor($Button1, $orange)
    $command = GUICtrlRead($Input1) & " -n " & GUICtrlRead($Input2) & " " & GUICtrlRead($Input3)
    GUICtrlSetData($Input4, $command)
    Local $text = '', $textalt = ''
    Local $Pid = Run(@ComSpec & ' /c ' & $command, '', @SW_HIDE, 2 + 4)
    AdlibEnable("pingen",20)
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button2
    Exit
    EndSwitch
    WEnd
    Func pingen()
    $text &= StdoutRead($Pid)
    If @error Then
    AdlibDisable()
    GuiCtrlSetBkColor($Button1, $green)
    Return
    EndIf
    If $textalt <> $text Then
    GUICtrlSetData($Edit1,$text)
    GUICtrlSetState($Edit1,$GUI_FOCUS)
    ControlSend("CMD - GUI","",$Edit1,"{PGDN}",0)
    $textalt = $text
    EndIf
    EndFunc

    [/autoit]

    Edit: Schreibfehler korrigiert

    MfG Schnuffel

    "Sarkasmus ist die niedrigste Form des Witzes, aber die höchste Form der Intelligenz."
    Val McDermid

    über mich...

    ich habe meine Erfahrungen hauptsächlich gesammelt in (grobe Übersicht):

    - RibbonBar Automation
    - MySQL Nutzung
    - GUIs in vielerlei Ausprägung
    - Nutzung von Powershell / Batch in AutoIt
    - Windows Automatisierung

    außerhalb von AutoIt:

    - Sprachen: PS, Batch, php, html(5), javascript, (perl eingeschränkt), vbs
    - Powershell (AD, WPF inkl. Multi-Threading, ...)
    - Deployment-Automatisierung ohne SCCM
    - Office-Nutzung mit COM-Object (AutoIt, PowerShell)
    - ActiveDirectory und alles was damit zusammenhängt
    - Hyper-V Clustering (Converged / Hyper Converged)
    - Serverhardware (Konfiguration, Aufbau, Architektur, Betrieb)

    Lieblingsthema:

    günstige Automatisierung von Vorgängen, für die andere Firmen viel Geld nehmen

    more to come ...