Sign in to follow this  
Followers 0
Wolfteeth

Embed Dos Command Window to GUI

5 posts in this topic

SIgh, couldn't find any answer for how to Embed Dos Command Window to GUI, someone can help to dig out the solution?

my purpose is to have button on click, such as "Ping www.ms.com" and then the results show inside my GUI instead of DOS command prompt window.

I don't want to use file read function to recall the text result but wanna to get the DOS results directly in my GUI program.

many thanks in advance.

Share this post


Link to post
Share on other sites



Here is a quick and dirty script I have for returning command prompt data via the StdoutRead method.

#include <GUIConstants.au3>
#include <Array.au3>
#Include <GuiEdit.au3>
#comments-start
This script allows DOS commands to be run via a GUI and output to the GUI Edit window.
The GUI can also output text in the GUI Edit window to be placed in the clipboard for easy retrieval.
#comments-end
;$command = ('dir /w c:')
GUICreate("Dir",400,340)
$Command = GUICtrlCreateInput("",10,280,300,20)
$Output = GUICtrlCreateEdit("",10,10,380,255)
$GoBtn = GUICtrlCreateButton("Go",270,305,40,20)
$Clip = GUICtrlCreateButton("Clipboard",320,305,65,20)
GUICtrlSetState($Clip, $GUI_DISABLE)
GUISetState(@SW_SHOW)
While 1
$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then ExitLoop
 
If $msg = $Clip Then
  $data = _GUICtrlEdit_GetText($Output)
  ClipPut($data)
 
  MsgBox(0,"","Contents Stored In Clipboard",.5)
EndIf

If $msg = $GoBtn Then
  _GUICtrlEdit_SetText($Output,"")
  $command = GUICtrlRead($Command)
  ;MsgBox(0,"",$command)
  _getDOSOutput($command)
  GUICtrlSetState($Clip, $GUI_ENABLE)
EndIf
WEnd
Func _getDOSOutput($command)
Local $text = '', $Pid = Run(@ComSpec & ' /c ' & $command, '', @SW_HIDE, 2 + 4)
While 1
  $text &= StdoutRead($Pid)
  If @error Then ExitLoop
WEnd
GUICtrlSetData($Output,$text)
EndFunc;==>_getDOSOutput

Share this post


Link to post
Share on other sites

although the above code doesn't work well but it realy gave me the idea on how to embed the output to STDout. many thanks.

Share this post


Link to post
Share on other sites

I thought it might give some issues after I posted the code; I wrote it a couple years back and I don't update my AutoIT version or scripts as much as I should. I'm glad I could be of some help though.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

SIgh, couldn't find any answer for how to Embed Dos Command Window to GUI, someone can help to dig out the solution?

my purpose is to have button on click, such as "Ping www.ms.com" and then the results show inside my GUI instead of DOS command prompt window.

I don't want to use file read function to recall the text result but wanna to get the DOS results directly in my GUI program.

many thanks in advance.

Hello Wolfteeth i was searching for a similar thing try this f it is helpful

This script belongs to user Country73 in post

#include 
#include 
#include 
Opt("GUIOnEventMode", 1)
Global  $MAIN, $CMD_WINDOW
Global  $IP_CONFIG, $OTHER, $BUTT_CLOSE
#Region ### START Koda GUI section ### Form=
$MAIN = GUICreate("CMD FUNCTIONS", 623, 449, 192, 114)
$CMD_WINDOW = GUICtrlCreateEdit("", 10, 10, 600, 289, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_READONLY,$WS_VSCROLL))
    GUICtrlSetFont($CMD_WINDOW, 12, 800, 0, "Times New Roman")
    GUICtrlSetColor($CMD_WINDOW, 0xFFFFFF)
    GUICtrlSetBkColor($CMD_WINDOW, 0x000000)
$IP_CONFIG = GUICtrlCreateButton("IP_CONFIG", 10, 310, 75, 25)
    GUICtrlSetOnEvent($IP_CONFIG, "_IP_CONFIGClick")
$OTHER = GUICtrlCreateButton("OTHER", 95, 310, 75, 25)
    GUICtrlSetOnEvent($OTHER, "_OTHERClick")
$BUTT_CLOSE = GUICtrlCreateButton("EXIT", 535, 310, 75, 25)
    GUICtrlSetOnEvent($BUTT_CLOSE, "_ExitNow")

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
    Sleep(100)
WEnd
Func _ExitNow()
    Exit
EndFunc
Func _IP_CONFIGClick()
    Local $foo = Run(@ComSpec & " /c " & "IPCONFIG /ALL",@SystemDir,@SW_HIDE,$STDOUT_CHILD)
    Local $line
    While 1
        $line = StdoutRead($foo)
        If @error Then ExitLoop
        If Not $line = "" Then GUICtrlSetData($CMD_WINDOW,$line)
    WEnd
EndFunc
Func _OTHERClick()
    GUICtrlSetData($CMD_WINDOW,"Create a CMD Function to be ran here")
EndFunc

or this, a bit old but also works for me, script belongs to user MrCreatoR from post

#include 
    Opt("GUIOnEventMode", 1)[/b]

Global $Init_Dir = "C:"
$Main_GUI = GUICreate("Embed Command Line Prompt", 550, 300, 10, 10)
GUISetOnEvent($GUI_EVENT_CLOSE, "Quit")
GUIRegisterMsg(0xF, "WM_PAINT")
$iCmd_PID = Run(@ComSpec & " /k CD " & $Init_Dir, "", @SW_HIDE)
ProcessWait($iCmd_PID)
$Embed_hWnd = _GetHWndByPID($iCmd_PID)
WinMove($Embed_hWnd, "", -2, -23, 549, 342)
WinSetState($Embed_hWnd, "", @SW_SHOWMINIMIZED)
GUISetState(@SW_SHOW, $Main_GUI)
DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $Embed_hWnd, "hwnd", $Main_GUI)

While 1
    Sleep(100)
    If WinActive($Main_GUI) Then WinActivate($Embed_hWnd)
WEnd
Func Quit()
    ProcessClose($iCmd_PID)
    Exit
EndFunc
Func _GetHWndByPID($iPID)
    Local $aWinList = WinList()
    For $i = 1 To UBound($aWinList)-1
        If WinGetProcess($aWinList[$i][1]) = $iPID Then Return $aWinList[$i][1]
    Next
    Return 0
EndFunc
Func WM_PAINT($hWnd, $Msg, $wParam, $lParam)
    DllCall("user32.dll", "int", "InvalidateRect", "hwnd", $hWnd, "ptr", 0, "int", 0)
EndFunc

I managed to bind both and have a nice script

Hope that helps.

Edited by armoros

[font="verdana, geneva, sans-serif"] [/font]

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
Sign in to follow this  
Followers 0