Trong

Autoit CMD

11 posts in this topic

#1 ·  Posted (edited)

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

 

Edited by Trong
#AutoIt3Wrapper_Au3Check_Parameters=-q -w 1 -w 2 -w 3 -w 4 -w 6 -w 7

“The world won’t care about your self-esteem. The world will expect you to accomplish something Before you feel good about yourself.”

Share this post


Link to post
Share on other sites



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?


When you're dead, you don't know you're dead - it's only difficult for those that know you. It's the same way when you're stupid...

My Scripts: SCCM UDFInclude Source with Compiled Script, Windows Firewall UDF

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I just want the script does not depend on #incude
 

;~ #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 by Trong
1 person likes this

“The world won’t care about your self-esteem. The world will expect you to accomplish something Before you feel good about yourself.”

Share this post


Link to post
Share on other sites

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.

1 person likes this

When you're dead, you don't know you're dead - it's only difficult for those that know you. It's the same way when you're stupid...

My Scripts: SCCM UDFInclude Source with Compiled Script, Windows Firewall UDF

Share this post


Link to post
Share on other sites

I already did something like this in my Process UDF's Debug function :P.


Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

@Trong There's a bug :)

1ea52ef1a9e1474293a22755dbf280eb.png

Share this post


Link to post
Share on other sites

@youtuber Not a bug, Encoding problem.

1 person likes this

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

26 minutes ago, TheDcoder said:

I already did something like this in my Process UDF's Debug function :P.

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 :)

1ea52ef1a9e1474293a22755dbf280eb.png

'list' is not recognized as an internal or external command,
operable program or batch file.

CMD not support OUTPUT Unicode!
OS vernacular!

Edited by Trong

“The world won’t care about your self-esteem. The world will expect you to accomplish something Before you feel good about yourself.”

Share this post


Link to post
Share on other sites
1 minute ago, Trong said:

I have just checked your UDF, it rather complicated.

Try running the example, its simple enough I think :huh:.

 

TD :)


Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

I appreciate the simplicity, speed and ability to integrate into other scripts!

I mean, I like the simplicity!

1 person likes this

“The world won’t care about your self-esteem. The world will expect you to accomplish something Before you feel good about yourself.”

Share this post


Link to post
Share on other sites

@Trong Glad you like it :D. I neglected that UDF a little over the months... Will get back it when I get some time :)

1 person likes this

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now