Examples of CMD in Autoit GUI! #include <GUIConstants.au3> #include <Constants.au3> Global $hGUI = GUICreate("AutoIt CMD", 604, 320, -1, -1) Global $cCommand = GUICtrlCreateInput("ping google.com", 64, 10, 416, 21) GUICtrlCreateLabel("CMD: >", 20, 15, 40, 20) Global $cExecute = GUICtrlCreateButton("Execute Command!", 485, 8, 112, 25) Global $cOutputBox = GUICtrlCreateEdit("", 10, 47, 578, 260, $ES_READONLY + $ES_MULTILINE + $WS_HSCROLL + $WS_VSCROLL + $ES_AUTOVSCROLL) ;$ES_READONLY=2048, $ES_MULTILINE=4, $WS_HSCROLL=0x00100000, $WS_VSCROLL=0x00200000, $ES_AUTOVSCROLL=64 GUICtrlSetData(-1, "") GUISetState(@SW_SHOW) Global $sCommand While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ; $GUI_EVENT_CLOSE=-3 Exit Case $cExecute $sCommand = GUICtrlRead($cCommand) If StringStripWS($sCommand, 8) <> "" Then GUICtrlSetState($cCommand, $GUI_DISABLE) ;$GUI_DISABLE=128 GUICtrlSetState($cExecute, $GUI_DISABLE) GUICtrlSetData($cExecute, " eXecuting..... ") _ExecuteCommandStream($sCommand) ;~ GUICtrlSetData($cOutputBox, _ExecuteCommand($sCommand)) GUICtrlSetData($cExecute, "Execute Command") GUICtrlSetState($cExecute, $GUI_ENABLE) ; $GUI_ENABLE=64 GUICtrlSetState($cCommand, $GUI_ENABLE) EndIf EndSwitch WEnd Func _ExecuteCommandStream($sCommand) Local $cCommandinfo = Run('"' & @ComSpec & '" /c ' & $sCommand, @ScriptDir, @SW_HIDE, $STDERR_MERGED) ;$STDERR_MERGED=8 Local $sOutput, $sOutputError While 1 GUICtrlSetData($cOutputBox, $sOutput & @CRLF) $sOutput &= StdoutRead($cCommandinfo) If @error Then ExitLoop Sleep(50) WEnd GUICtrlSetData($cOutputBox, $sOutput & @CRLF) EndFunc ;==>_ExecuteCommandStream Func _ExecuteCommand($sCommand) Local $cCommandinfo = Run('"' & @ComSpec & '" /c ' & $sCommand, @ScriptDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD + $STDIN_CHILD) ;$STDERR_CHILD=4, $STDOUT_CHILD=2, $STDIN_CHILD=1 Local $sOutput, $sOutputError While 1 $sOutput &= StdoutRead($cCommandinfo) If @error Then ExitLoop WEnd While 1 $sOutputError &= StderrRead($cCommandinfo) If @error Then ExitLoop WEnd If $sOutput <> '' Then Return $sOutput ElseIf $sOutputError <> '' Then Return SetError(0, 1, $sOutputError) Else Return SetError(0, 2, "") EndIf EndFunc ;==>_ExecuteCommand