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
#include <Constants.au3>
Global $CmdFile, $Command, $filewrite, $hide
Func _CMD($Command)
Run(@ComSpec & " /c " & $Command, @SystemDir, @SW_HIDE)
EndFunc
;===============================================================================
;
; 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
;
;===============================================================================
Func _CMDStart($invisible)
If $invisible = "0" Then
$hide = 0
ElseIf $invisible = "1" Then
$hide = 1
EndIf
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
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)
;
;===============================================================================
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
;===============================================================================
;
; 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
;
;===============================================================================
Func _CMDEnd()
FileClose($CmdFile)
If $hide = 1 Then
RunWait(@TempDir & "\temp.bat", "", @SW_HIDE)
ElseIf $hide = 0 Then
RunWait(@TempDir & "\temp.bat", "", @SW_SHOW)
EndIf
[/autoit] [autoit][/autoit] [autoit]FileDelete(@TempDir & "\temp.bat")
EndFunc ;==>_CMDEnd
;===============================================================================
;
; 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
$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
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?????