Programm (Script) soll AutoIt-Code ausführen.

  • Abend Leute,

    ich habe eine Frage und zwar, wie kann ich ein Programm so schreiben das er ein AutoIt-Code von einer reinen Text-Datei, z.B. .au3, .txt etc. ausführen kann? Wäre echt nett. Danke.

    MfG

    MehmeX

  • Wie meinst du das? Hier ein Beispiel bei dem die Datei dem Skript als Parameter übergeben wird.

    Spoiler anzeigen
    [autoit]

    If $CmdLine[0] = 1 Then
    If FileExists($CmdLine[1]) Then
    If StringRight($CmdLine[1], 4) = '.au3' Or StringRight($CmdLine[1], 4) = '.txt' Then
    Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & $CmdLine[1] & '"')
    EndIf
    EndIf
    EndIf

    [/autoit]
  • Ein Programm bzw. ein Script soll ein Textdokument in der ein Scriptbefehl ist, ausführen. In dem Textdokument könnte folgendes drinnen stehen:

    [autoit]

    GUICreate("Test")

    [/autoit]

    Aber wenn ich mir genauer überlege geht es ja wahrscheinlich eh nicht, denn die Programmiersprache (AutoIt) muss ja vom Programm, also AutoIt, erkannt werden und kann nicht von einem Script gelesen werden.

  • Ja, oder du brauchst sehr viele If anweisungen...

    [autoit]

    If FileReadline (...) == ... Then ...

    [/autoit]


    :D

    Theorie ist wenn man weiß wie's geht, aber nichts klappt.
    Praxis ist wenn's klappt aber man weiß nicht weiso.

    Bei Microsoft sind Theorie und Praxis vereint: Nichts klappt und keiner weiß wieso ;)

    • Offizieller Beitrag

    Hallo

    Spoiler anzeigen
    [autoit]

    If Not @Compiled Then Exit MsgBox(16,"","Warnung! Das Script muss zuerst Kompiliert werden!")
    $sFile2Run = FileOpenDialog("Datei wo AutoIt Code drin ist","","alle (*.*)")
    RunWait(@ScriptFullPath&' /AutoIt3ExecuteScript "'&$sFile2Run&'"')
    MsgBox(0,"","Der Code wurde ausgeführt!")

    [/autoit]

    Mfg Spider

  • Hallo,
    ggf reicht schon der Befehl Execute()

    [autoit]

    $anweisung='msgbox(0,"Anweisung","Anweisung wurde ausgeführt!")'
    execute($anweisung)

    [/autoit]


    ciao
    Andy

  • Das habe ich auch versucht hat aber irgendwie nicht geklappt, hmm. Denn ich habe es mit FileRead usw. gemacht, kann sein dass es dem lag.


    EDIT: Ich habe es mal so probiert und es funktioniert nicht, denn mit FileRead usw. funktioniert es auch, wenn MsgBox drinn steht. Wenn aber ein GUI-Befehl drinnen steht geht es nicht.

    [autoit]

    $anweisung='GUICreate("Test")'
    execute($anweisung)

    [/autoit]

    3 Mal editiert, zuletzt von MehmeX (12. Juli 2009 um 19:53)

  • Hallo,
    wenn sticky, dann mit meinem Lieblingsbeispiel^^

    Spoiler anzeigen
    [autoit]

    #include <Misc.au3>
    $MsgBoxValue = _MsgBoxChangeButtons(4, 'This is my msgbox', 'This' & @CRLF & 'Should' & @CRLF & 'Work', 'ReBoot', 'Continue')
    If $MsgBoxValue = 6 Then MsgBox(0, 'Clicked', 'You clicked the ReBoot Button')

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

    Func _MsgBoxChangeButtons($iFlag, $sTitle, $sText, $sButton1, $sButton2 = '', $sButton3 = '', $iMBTimeOut = 0)
    Local $MBFile = FileOpen(@TempDir & '\MiscMMB.txt', 2)
    Local $MBLine1 = 'While Not WinExists("' & $sTitle & '")'
    Local $MBLine2 = ' Sleep(10)'
    Local $MBLine3 = 'WEnd'
    Local $MBLine4 = 'ControlSetText("' & $sTitle & '", "", "Button1", "' & $sButton1 & '")'
    Local $MBLine5 = 'ControlSetText("' & $sTitle & '", "", "Button2", "' & $sButton2 & '")'
    Local $MBLine6 = 'ControlSetText("' & $sTitle & '", "", "Button3", "' & $sButton3 & '")'
    If $sButton2 = '' Then
    FileWrite(@TempDir & '\MiscMMB.txt', $MBLine1 & @CRLF & $MBLine2 & @CRLF & $MBLine3 & @CRLF & $MBLine4)
    ElseIf $sButton2 <> '' And $sButton3 = '' Then
    FileWrite(@TempDir & '\MiscMMB.txt', $MBLine1 & @CRLF & $MBLine2 & _
    @CRLF & $MBLine3 & @CRLF & $MBLine4 & @CRLF & $MBLine5)
    ElseIf $sButton2 <> '' And $sButton3 <> '' Then
    FileWrite(@TempDir & '\MiscMMB.txt', $MBLine1 & @CRLF & $MBLine2 & @CRLF & _
    $MBLine3 & @CRLF & $MBLine4 & @CRLF & $MBLine5 & @CRLF & $MBLine6)
    EndIf
    $MBPID1 = Run(@AutoItExe & ' /AutoIt3ExecuteScript ' & EnvGet('TEMP') & '\MiscMMB.txt')
    $MBBox = MsgBox($iFlag, $sTitle, $sText, $iMBTimeOut)
    FileClose($MBFile)
    Do
    FileDelete(@TempDir & '\MiscMMB.txt')
    Until Not FileExists(@TempDir & '\MiscMMB.txt')
    Return $MBBox
    EndFunc

    [/autoit]

    und einen Kommentar dazu:

    Zitat

    I understand the scary part... boy, do I understand!
    Some of these guys are pros - and then there is me :)


    So gehts mir auch :D
    ciao
    Andy