Trong Posted June 3, 2016 Share Posted June 3, 2016 (edited) Examples of CMD in Autoit GUI! expandcollapse popup#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 Edited June 6, 2016 by Trong #AutoIt3Wrapper_Au3Check_Parameters=-q -w 1 -w 2 -w 3 -w 4 -w 6 -w 7 zoel 1 Regards, Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted June 3, 2016 Moderators Share Posted June 3, 2016 Is there a reason you always include all of your commented-code in your final script? Obviously the usefulness of this script would be limited to someone who is relatively new to AutoIt, so don't you think all the commented-out code with no explanation might confuse them? "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Trong Posted June 3, 2016 Author Share Posted June 3, 2016 (edited) I just want the script does not depend on #incude expandcollapse popup;~ #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, 2048 + 4 + 0x00100000 + 0x00200000 + 64) ;$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 -3 Exit Case $cExecute $sCommand = GUICtrlRead($cCommand) If StringStripWS($sCommand, 8) <> "" Then GUICtrlSetState($cCommand, 128) ;$GUI_DISABLE=128 GUICtrlSetState($cExecute, 128) GUICtrlSetData($cExecute, " eXecuting..... ") _ExecuteCommandStream($sCommand) ;~ GUICtrlSetData($cOutputBox, _ExecuteCommand($sCommand)) GUICtrlSetData($cExecute, "Execute Command") GUICtrlSetState($cExecute, 64) ; $GUI_ENABLE=64 GUICtrlSetState($cCommand, 64) EndIf EndSwitch WEnd Func _ExecuteCommandStream($sCommand) Local $cCommandinfo = Run('"' & @ComSpec & '" /c ' & $sCommand, @ScriptDir, @SW_HIDE, 8) ;$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, 4 + 2 + 1) ;$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 Edited June 6, 2016 by Trong Regards, Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted June 3, 2016 Moderators Share Posted June 3, 2016 I see where you did this in answer to a question in GH&S. I personally would not suggest starting someone new off with Magic Numbers rather than best practices - it isn't going to do them any favors as they learn to script. Trong 1 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
TheDcoder Posted June 3, 2016 Share Posted June 3, 2016 I already did something like this in my Process UDF's Debug function . EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
youtuber Posted June 3, 2016 Share Posted June 3, 2016 @Trong There's a bug Link to comment Share on other sites More sharing options...
TheDcoder Posted June 3, 2016 Share Posted June 3, 2016 @youtuber Not a bug, Encoding problem. youtuber 1 EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
Trong Posted June 3, 2016 Author Share Posted June 3, 2016 (edited) 26 minutes ago, TheDcoder said: I already did something like this in my Process UDF's Debug function . I did not know it earlier! I have just checked your UDF, it rather complicated. A function to be used to a lot of other functions and up to 625 lines when compiler. 15 minutes ago, youtuber said: @Trong There's a bug 'list' is not recognized as an internal or external command, operable program or batch file. CMD not support OUTPUT Unicode! OS vernacular! Edited June 3, 2016 by Trong Regards, Link to comment Share on other sites More sharing options...
TheDcoder Posted June 3, 2016 Share Posted June 3, 2016 1 minute ago, Trong said: I have just checked your UDF, it rather complicated. Try running the example, its simple enough I think . TD EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
Trong Posted June 3, 2016 Author Share Posted June 3, 2016 I appreciate the simplicity, speed and ability to integrate into other scripts! I mean, I like the simplicity! Regards, Link to comment Share on other sites More sharing options...
TheDcoder Posted June 3, 2016 Share Posted June 3, 2016 @Trong Glad you like it . I neglected that UDF a little over the months... Will get back it when I get some time Trong 1 EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now