Jump to content

Command Prompt


Go to solution Solved by MHz,

Recommended Posts

I m still confused how to make this DOS window work with series of command entering using StdinWrite($DOS, 'dir/whatever' & @CRLF) instead of using button ..

how to update the edit /dos window after that  and to read the output from dos.

Mine doesn't work yet ..Would you give me some hints.

Link to comment
Share on other sites

I m still confused how to make this DOS window work with series of command entering using StdinWrite($DOS, 'dir/whatever' & @CRLF) instead of using button ..

how to update the edit /dos window after that  and to read the output from dos.

Mine doesn't work yet ..Would you give me some hints.

 

something like this could do,

be aware that if you send an "endless" dos command (example: ping localhost -t),  the sub will never return back

#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GuiEdit.au3>

Global $DOS = Run(@ComSpec & " /K", "", @SW_HIDE, $STDERR_MERGED + $STDIN_CHILD) ; run in background an hidden cmd

$hGUI = GUICreate("Command Prompt", 600, 326)
$hEdit = GUICtrlCreateEdit('', 0, 0, 600, 297, BitOR($WS_VSCROLL, $ES_AUTOVSCROLL, $ES_WANTRETURN, $ES_READONLY))
GUICtrlSetFont(-1, 10, 400, 0, "Lucida Console")
GUICtrlSetBkColor(-1, 0x000000)
GUICtrlSetColor(-1, 0x00FF00) ; Text color green
GUISetState(@SW_SHOW)

; -----------------------------
MsgBox(0, "Output", Dos("dir"))
$result = Dos("ping " & @ComputerName)
MsgBox(0, "Output", $result)
; -----------------------------

Func Dos($cmd)
    Local $tail = '' ; clear tail
    Switch $cmd
        Case "exit"
            ; StdinWrite($DOS, 'Exit' & @CRLF)
            ; ProcessWaitClose($DOS)
            Return "exit not allowed"
        Case "cls"
            ; clear screen using cls
            GUICtrlSetData($hEdit, '')
            Return ""
    EndSwitch
    StdinWrite($DOS, $cmd & @CRLF) ; send dos command
    While 1
        $Stdout = StdoutRead($DOS) ; get output from command
        If @extended Then ; if there is output then
            $tail &= $Stdout ; add to tail
            ; read edit ctrl
            $sEdit = GUICtrlRead($hEdit)
            ; limit size in edit to prevent reaching full limit
            If StringLen($sEdit) > 15000 Then
                GUICtrlSetData($hEdit, StringRight($sEdit, 15000)) ; leave only last 15000 chars of "buffer"
            EndIf
            GUICtrlSetData($hEdit, $Stdout, True) ; append stdout to edit ctrl
        ElseIf StringRight($tail, 1) = '>' Then
            Return StringStripWS(StringMid(StringLeft($tail, StringInStr($tail, @CR, 0, -1)), StringInStr($tail, @CR, 0, 1)), 3)
        EndIf
    WEnd
EndFunc   ;==>Dos

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

PincoPanco, thank you very much. It works awesomely.

I ll use this to run some perl script on Dos window  and read output from them ..

I didn't know it needs a loop for reading the stdoutput hehe.

I used std write and then read right after ..it never shows any result..Thnks again for your wonderful help

Link to comment
Share on other sites

PincoPanco, thank you very much. It works awesomely.

I ll use this to run some perl script on Dos window  and read output from them ..

I didn't know it needs a loop for reading the stdoutput hehe.

I used std write and then read right after ..it never shows any result..Thnks again for your wonderful help

 

You are welcome :)

p.s.

take a look also to some >other ways to use cmd

edit:

also here

Edited by PincoPanco

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

how can I exit out of the current process of a dos command without losing the main dos window?

for example I ran a bat file to set up a profile ...this normally takes 7 min or longer until it shows up the promt > ..and I wnt to ends it for something else?

Edited by iahngy
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...