• Hallo

    da ich nun schon öfters auf das Problem des DOS-Kommando-Nutzens in AutoIt gestoßen bin hab ich mir dazu eine UDF geschrieben
    (meine erste^^ also seid bitte etwas nachsichtig)
    sagt mir aber bitte trotzdem alle bugs und ob euch noch etwas dazu einfällt in Hinsicht auf Verbesserungen

    Spoiler anzeigen
    [autoit]


    #include <Constants.au3>
    Global $CmdFile, $Command, $filewrite, $hide

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

    Func _CMD($Command)
    Run(@ComSpec & " /c " & $Command, @SystemDir, @SW_HIDE)
    EndFunc

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

    ;===============================================================================
    ;
    ; Description: Initiates the _CMDWrite-process
    ; Syntax: _CMDStart( $invisible )
    ; Parameter(s): $invisible - If 1 the CMD-Window is invisible
    ; Requirement(s): None
    ; Return Value(s): On Success - Sets @error to 0.
    ; On Failure - Returns 0 and sets @error to 1.
    ; Author(s): Padmak <[email='padmak@web.de'][/email]>
    ; Note(s): None
    ;
    ;===============================================================================

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

    Func _CMDStart($invisible)
    If $invisible = "0" Then
    $hide = 0

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

    ElseIf $invisible = "1" Then
    $hide = 1
    EndIf

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

    FileDelete(@TempDir & "\temp.bat")

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

    $CmdFile = FileOpen(@TempDir & "\temp.bat", 2)

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

    If $CmdFile = -1 Then
    SetError(@error, @extended, 1)
    Return 0
    Else
    SetError(@error, @extended, 0)
    EndIf

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

    EndFunc ;==>_CMDStart

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

    ;===============================================================================
    ;
    ; Description: Writes the CMD-Command
    ; Syntax: _CMDStart( $Command )
    ; Parameter(s): $Command - Command to execute
    ; Requirement(s): None
    ; Return Value(s): On Success - Sets @error to 0.
    ; On Failure - Sets @error to 1.
    ; Author(s): Padmak <[email='padmak@web.de'][/email]>
    ; Note(s): If you come from an non-german-speaking country, replace
    ; "pause" with your expression of the command (the break-command)
    ;
    ;===============================================================================

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

    Func _CMDWrite($Command)
    $file = FileExists(@TempDir & "\temp.bat")
    If $hide = 1 And $file = 1 Then
    $string = StringReplace($Command, "pause", "") ;<=======Replace here
    If Not @extended = 0 Then MsgBox(0, "Error", "You mustn't use a Pause-Command in the hide-mode") ;<======= Replace here again
    ElseIf $file = 1 Then
    $filewrite = FileWriteLine($CmdFile, $Command & @CRLF)
    If $filewrite = 0 Then SetError(@error, @extended, 1)
    Else
    SetError(@error, @extended, 0)
    EndIf
    EndFunc ;==>_CMDWrite

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

    ;===============================================================================
    ;
    ; Description: Closes the _CMDWrite-Process and starts the commands
    ; Syntax: _CMDStart( )
    ; Parameter(s): None
    ; Requirement(s): None
    ; Return Value(s): None
    ; Author(s): Padmak <[email='padmak@web.de'][/email]>
    ; Note(s): None
    ;
    ;===============================================================================

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

    Func _CMDEnd()
    FileClose($CmdFile)

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

    If $hide = 1 Then
    RunWait(@TempDir & "\temp.bat", "", @SW_HIDE)

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

    ElseIf $hide = 0 Then
    RunWait(@TempDir & "\temp.bat", "", @SW_SHOW)

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

    EndIf

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

    FileDelete(@TempDir & "\temp.bat")
    EndFunc ;==>_CMDEnd

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

    ;===============================================================================
    ;
    ; Description: Executes a DOS command in a hidden command window and gives
    ; back the text of the window.
    ; Syntax: _CMDRead( $Command )
    ; Parameter(s): $Command - Command to execute
    ; Requirement(s): None
    ; Return Value(s): On Success - Returns the value of the command window
    ; On Failure - Returns 0 and sets @error to non-zero.
    ; Author(s): Padmak <[email='padmak@web.de'][/email]>
    ; Note(s): None
    ;
    ;===============================================================================
    Func _CMDRead($Command)
    Local $CMDRead

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

    $CMD = Run(@ComSpec & " /c " & $Command, @SystemDir, @SW_HIDE, $STDOUT_CHILD)

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

    While 1
    $CMDRead &= StdoutRead($CMD)
    If @error Then ExitLoop
    WEnd
    Return $CMDRead
    EndFunc ;==>_CMDRead

    [/autoit]

    Padmak

    Edit: Bisschen was angepasst
    Edit2: Ich finds ja toll dass fast 40 leute vorbei schaun aba keiner schreibt was...

    Edit3: 50 leute und keine kritik????
    soll ich das jez positiv sehen?????

    3 Mal editiert, zuletzt von Padmak (29. Dezember 2008 um 14:02)

  • Hi,
    na dann will ich mal.
    Meine Frage wäre nur wozu ne UDF für cmd unter Dos? Ich nutze in vielen Skripts die cmd Funktion und habe noch nie eine UDF vermisst.

    CMD benutzen

    Spoiler anzeigen
    [autoit]


    $pid = Run(@ComSpec & " /c ipconfig /all", "", "", 2)

    [/autoit]

    CMD Rückgabe

    Spoiler anzeigen
    [autoit]


    While 1
    if StdOutRead($pid,0,True) <> 0 then
    $ausgabe &= StdOutRead($pid)
    EndIf
    If @error Then ExitLoop
    Sleep(50)
    WEnd

    [/autoit]

    Muss natürlich sagen das die Rückgabe net die beste ist, habe aber leider das aktuelle Script nicht bei mir und merken kann ich mir sowas immer net.

    MfG
    Der_Doc

    • Offizieller Beitrag

    Hallo

    Ausgabe in die Konsole kannst du jetzt auch mit ConsoleWrite machen, wenn du dein Skript als CUI (Console User Interface) Version Kompelierst.
    Trotzdem, für deine erste UDF ist das schon gut :)
    Auch schon übersichtlich mit den Kommentaren usw.

    Was du vielleicht das nächste mal beachten könntest, währe vor den Variablennamen den Ihnalt der Variable angeben. Also was für ein Format die Variable ist
    Für ein Integer(eine Zahl) i und für ein String(Text) ein s, usw.
    Also z.B.
    Func _CMDStart($iInvisible)
    oder
    Func _CMDWrite($sCommand)

    Mfg Spider

  • [autoit]

    Func _CMDStart($invisible=0)

    [/autoit]

    Hier könnte noch ein Standard Wert rein, der wenn man keinen Parameter angibt z.B. immer das Konsolenfenster zeigt.

    • Offizieller Beitrag

    Hi,

    für den einen Ansatz gab es doch schon welche

    [autoit]

    Global $re = _getDOSOutput('ipconfig /all')

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

    MsgBox(64, 'IPCONFIG / ALL', StringStripWS($re, 7), 20)

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

    Func _getDOSOutput($command)
    Local $text = '', $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

    [/autoit]


    Aber weiter so!!! :P

    Mega

  • Der_Doc
    Es ist einfach so dass man mit autoit ohne hilfe kein --> MEHRZELIGEN <-- DOS-Kommandos schreiben kann

    GtaSpider
    Danke dass ich das von dir hören darf *freu^^*

    Zitat

    Ausgabe in die Konsole kannst du jetzt auch mit ConsoleWrite machen, wenn du dein Skript als CUI (Console User Interface) Version Kompelierst.

    CUI = ???
    was ist das^^
    und gehen damit dos-kommandos?
    und ja des mit den Variablen werd ich mir angewöhnen

    und Xenobiologist
    wo hast du das her? das hab ich nirgends trotz langer Recherche gefunden...
    ^^
    Padmak

  • Ich find die UDF auch ganz klasse.


    Aber mein problem ist bis jetz wie soll ich die CMD box schließen ohne das programm zu killen mit einem exit also nur die CMD box will ich killen.


    Des weiteren würde ich gerne die cmd box rechts oben auf meinem bildschirm packen.....


    das wärden noch coole sachen für die udf.... oder ist das garnet mit autoit möglich


    also was ich meine ist ein _CMDStop()

    und vlt ein _CMDPos(x,y)


    MFG Matthias

  • das cmd fenster wurde mit der udf hier erstellt und solange mein programm aktive ist ist das fenster auch da,
    ich benötige es eben nur nicht mehr im letzten teil meines programmes und wen es da noch rumgruvkt stört des eben