Unerklärliche Schleife

  • Hallo zusammen

    Ich kann mir folgende Situation beim besten willen nicht erklären. Folgender Code:

    Spoiler anzeigen
    [autoit]


    #include "ConsoleControl.au3"
    #include "MyLib.au3"
    Global Const $_Console_USEWINDOW = False
    _ConsoleStartup()
    ShellExecute(@AutoItExe, "X:\Client\Source\Client.au3")
    MsgBox(0, "1", @error)
    Sleep(1000)
    _ServiceStartup()
    MsgBox(0, "2", @error)
    _ConsoleWrite("Willkommen" & @CRLF)

    [/autoit]

    Die Funktion _ServiceStartup():

    Spoiler anzeigen
    [autoit]


    Func _ServiceStartup()
    Local $iListen
    Global $idClientSocket = -1, $idServerSocket = -1
    TCPStartup()
    $idClientSocket = TCPConnect(@IPAddress1, 50000)
    $iListen = TCPListen(@IPAddress1, 50001)
    Do
    $idServerSocket = TCPAccept($iListen)
    Until $idServerSocket <> -1
    EndFunc ;==>_ServiceStartup

    [/autoit]

    Und noch der Inhalt der ConsoleControl.au3:

    Spoiler anzeigen
    [autoit]


    #cs
    Put the following two lines in your Script to use CMD-Funtions:

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

    #include
    ; These two lines, if the existing Console should be used, if possible
    #AutoIt3Wrapper_Change2CUI=y
    Global Const $_Console_USEWINDOW = True
    ; This line, if always a new Console should be created:
    ;~ Global Const $_Console_USEWINDOW = False

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

    #ce

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

    #include
    Global $GLOBAL_hConsole, $GLOBAL_hConsoleIn, $CMD_INFINITE = 0xFFFFFFFF
    ; Initialize the CMD Funcs
    ; Parameter: [Opt] $ExitOnFatal - If True, The App exits with Fatal error if an error occurs in this Function (Default: False)
    ; Return values: Success: 1
    ; Error: 0 and @error:
    ; 1 - Could not allocate Console -> no In or outuput-Handle
    ; 2 - GetStdHandle for Output failed -> No Output-Handle, too
    ; 3 - GetStdHandle for Input failed, but we have an Ouput-Handle
    ;Author: Prog@ndy
    Func _ConsoleStartup($ExitOnFatal = 0)
    If Not @Compiled Then
    If Not IsDeclared("_Console_USEWINDOW") Then
    #Region --- CodeWizard generated code Start ---
    ;MsgBox features: Title=Yes, Text=Yes, Buttons=Yes and No, Default Button=Second, Icon=Critical
    If 6 = MsgBox(276, "No Console App specified!", "You hav to copy these lines to your main-Script, just before you call _Console_STARTUP:" & @CRLF & "; These two lines, if the CMD-Console should be used, if possible" & @CRLF & " #AutoIt3Wrapper_Change2CUI=y" & @CRLF & " Global $_Console_USEWINDOW = True" & @CRLF & "; This line, if always a new Console should be created:" & @CRLF & " Global $_Console_USEWINDOW = False" & @CRLF & @CRLF & " COPY TO CLIPBOARD?") Then
    ClipPut("; These two lines, if the CMD-Console should be used, if possible" & @CRLF & _
    "#AutoIt3Wrapper_Change2CUI=y" & @CRLF & _
    "Global Const $_Console_USEWINDOW = True" & @CRLF & _
    "; This line, if always a new Console should be created:" & @CRLF & _
    ";~ Global Const $_Console_USEWINDOW = False")
    EndIf
    EndIf
    MsgBox(16, 'Console UDF error', "Console does not work in uncompiled scripts.")
    Exit
    EndIf
    If Not IsDeclared("_Console_USEWINDOW") Then Local $_Console_USEWINDOW = True
    If Not $_Console_USEWINDOW Or ($_Console_USEWINDOW And (Not _WinAPI_AttachConsole())) Then
    $ret = DllCall("Kernel32.dll", "long", "FreeConsole")
    $ret = DllCall("Kernel32.dll", "long", "AllocConsole")
    If $ret = 0 Then
    If $ExitOnFatal Then _WinAPI_FatalAppExit("Could not allocate Console")
    Return SetError(1, 0, 0)
    EndIf
    $HWND = DllCall("kernel32.dll", "hwnd", "GetConsoleWindow")
    WinSetState($HWND[0], "", @SW_SHOW)
    EndIf
    Global $GLOBAL_hConsole = _WinAPI_GetStdHandle(1)
    If $GLOBAL_hConsole = -1 Then
    If $ExitOnFatal Then _WinAPI_FatalAppExit("GetStdHandle for Output failed")
    Return SetError(2, 0, 0)
    EndIf
    DllCall("Kernel32.dll", "long", "SetConsoleActiveScreenBuffer", "handle", $GLOBAL_hConsole)
    Global $GLOBAL_hConsoleIn = _WinAPI_GetStdHandle(0)
    If $GLOBAL_hConsoleIn = -1 Then
    If $ExitOnFatal Then _WinAPI_FatalAppExit("GetStdHandle for Input failed")
    Return SetError(1, 0, 0)
    EndIf
    Return 1
    EndFunc ;==>_Console_STARTUP

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

    ; PASUES CMD, waits for any key
    ; Author: ProgAndy
    Func _ConsolePause($iTime = -1)
    Local $ret, $Key_Event = False
    _ConsoleWrite("PAUSE: Press any key to continue ")
    DllCall("Kernel32.dll", "long", "FlushConsoleInputBuffer", "handle", $GLOBAL_hConsoleIn)
    Local $tInp = DllStructCreate("long;uint64[4]")
    Do
    $ret = DllCall("Kernel32.dll", "long", "WaitForSingleObject", "handle", $GLOBAL_hConsoleIn, "dword", $iTime)
    If @error Then Return SetError(1, 0, 0)
    If $ret[0] = -1 Then Return SetError(2, 0, 0)
    Local $rce = DllCall("kernel32.dll", "bool", "ReadConsoleInput", "handle", $GLOBAL_hConsoleIn, "ptr", DllStructGetPtr($tInp), "dword", 1, "dword*", 0)
    $Key_Event = DllStructGetData($tInp, 1) = 1
    Until ($Key_Event And $rce[4]) Or $ret[0] = 0x00000102
    DllCall("Kernel32.dll", "long", "FlushConsoleInputBuffer", "handle", $GLOBAL_hConsoleIn)
    Return SetExtended($ret[0] = 0x00000102, 1)
    EndFunc ;==>_Console_Pause

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

    Func _ConsoleClose()
    Local $ret = DllCall("Kernel32.dll", "int", "FreeConsole")
    If @error Then Return SetError(1, 0, 0)
    Return SetError($ret[0] <> 0, 0, $ret[0])
    EndFunc ;==>_Console_Close

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

    ;Writes Text to CMD
    ; Author: ProgAndy
    Func _ConsoleWrite($text)
    Local $temp = _WinAPI_WriteConsole($GLOBAL_hConsole, $text)
    Return SetError(@error, @extended, $temp)
    EndFunc ;==>_Console_Write

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

    ;Reads Text from CMD
    ; Author: ProgAndy
    Func _ConsoleRead($pInputControl = 0)
    Local $tBuffer = DllStructCreate("wchar[4000]")
    Local $aResult = DllCall("Kernel32.dll", "int", "ReadConsoleW", "handle", $GLOBAL_hConsoleIn, "ptr", DllStructGetPtr($tBuffer), "DWORD", 4000, "dword*", 0, "ptr", $pInputControl)
    If @error Then Return SetError(1, @error, "")
    If $aResult[0] = 0 Then Return SetError(2, 0, "")
    Return StringLeft(DllStructGetData($tBuffer, 1), $aResult[4])
    EndFunc ;==>_Console_Read

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

    ; Writes the prompt and then reads Text from CMD
    ; Author: ProgAndy
    Func _Console_Ask($sPrompt)
    _ConsoleWrite($sPrompt)
    If @error Then Return SetError(1, @error, "")
    Local $sBuff = _ConsoleRead()
    If @error Then Return SetError(2, @error, "")
    Return $sBuff
    EndFunc ;==>_Console_Ask

    [/autoit]

    Die Beiden MsgBoxen sind nur zur Fehlersuche da. Die Client.au3 Stellt nur eine TCP-Verbindung mir dem Script (siehe _ServiceStartup()) her und geht dann in eine Schleife.
    Wenn ich das ganze nun Kompiliere, öffnet sich erst eine Konsole und dann die erste MsgBox. Danach öffnet sich jedoch gleich wider eine Konsole und eine MsgBox.
    Und das im Eiltempo immer wider. Am Schluss hatte ich so viele Fenster dadurch offen, dass ich meinen PC ausschalten musste. Ich hab sie sonst nicht mehr weggebracht.
    Kann mir das einer von euch erklären????

  • Fehler liegt vermutlich in der Client.au3, ich sehe in dem was du bislang gepostet hast jedenfalls nichts was in einer Schleife zum shellexecute führt. Erklären kann ich mir das nur wenn die client.au3 identisch zu deinem ersten codeblock ist, denn dann ruft sich das script immer wieder selbst auf.

  • Das ist mir schon klar. So ist es natürlich nicht. Hier ist sonst noch die Client.au3:

    Spoiler anzeigen
    [autoit]


    TCPStartup()
    $_LocalTemp = TCPListen(@IPAddress1, 50000)
    $idServerSocket = -1
    Do
    $idServerSocket = TCPAccept($_LocalTemp)
    Until $idServerSocket <> -1
    Global $idClientSocket = -1
    $idClientSocket = TCPConnect(@IPAddress1, 50001)

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

    While 1
    Sleep(100) ; Hier kommt dann später noch etwas
    WEnd

    [/autoit]

    Hat sonst noch jemand eine Idee?

  • Ahja nun hab ich den Fehler entdeckt. Es ist fast wie ich vermutet habe. Du lässt dein Script sich selbst aufrufen.

    [autoit]

    @AutoItExe ; Der komplette Pfad und Dateiname der AutoIt-Exe-Datei. Bei kompilierten Skripten der Pfad des laufenden Skriptes.

    [/autoit]

    Bedeutet: shellexecute(deinescript.exe, "mit parameter client.au3")

    Das was du aber eigentlich erreichen wolltest war ja den autoit interpreter mit parameter aufzurufen, nicht dein eigenes laufendes script. ;)
    In kompilierter Form darfst du das Makro so also nicht verwenden.