Sign in to follow this  
Followers 0
Shredplayer

Sending control-c to a hidden cmd window

6 posts in this topic

i'm having problem on how to send control-c to stop "ping -t www.google.com", it won't send any commands because autoit won't process any request as long ping is in loop, here's my code and hope you can help me.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiEdit.au3>
#include <Constants.au3>
#include <ScrollBarConstants.au3>
 
$Form1 = GUICreate("Pinger", 328, 270, 192, 124)
$url = GUICtrlCreateInput("", 78, 21, 233, 21)
$Label1 = GUICtrlCreateLabel("Address :", 21, 23, 48, 17)
$Edit1 = GUICtrlCreateEdit("", 18, 49, 293, 165)
GUICtrlSetData(-1, "")
$start = GUICtrlCreateButton("Start", 233, 229, 75, 25, 0)
$stop = GUICtrlCreateButton("Stop", 156, 230, 75, 25, 0)
GUISetState(@SW_SHOW)
 
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $start
  Pinger()
  Case $stop
  Consolewrite("Don't know how to stop")
EndSwitch
WEnd
Func Pinger ()
GUICtrlSetData($Edit1, "")
GUICtrlSetState ($start,$GUI_DISABLE)
$address = GUICtrlRead($url)
$ping = Run("ping.exe -t " & GUICtrlRead($url), "", @SW_HIDE,$STDERR_CHILD + $STDOUT_CHILD)
while 1
$line = StdoutRead($ping & @CRLF)
if @error then ExitLoop
_GUICtrlEdit_AppendText($Edit1,$Line)
_GUICtrlEdit_Scroll($Edit1, $SB_SCROLLCARET)
sleep(100)
Wend
GUICtrlSetState ($start,$GUI_ENABLE)
StdioClose($ping)
EndFunc

Share this post


Link to post
Share on other sites



any ideas guys?

Share this post


Link to post
Share on other sites

ok 'ill look into it thanks

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Something to play with:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>
#include <Constants.au3>
#include <ScrollBarConstants.au3>

$Form1 = GUICreate("Pinger", 328, 270, 192, 124)
$url = GUICtrlCreateInput("", 78, 21, 233, 21)
$Label1 = GUICtrlCreateLabel("Address :", 21, 23, 48, 17)
$Edit1 = GUICtrlCreateEdit("", 18, 49, 293, 165)
GUICtrlSetData(-1, "")
$start = GUICtrlCreateButton("Start", 233, 229, 75, 25, 0)
$stop = GUICtrlCreateButton("Stop", 156, 230, 75, 25, 0)
GUICtrlSetState($stop, $GUI_DISABLE)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $start
            Pinger()
        Case $stop
            ConsoleWrite("Don't know how to stop")
    EndSwitch
WEnd
Func Pinger()
    GUICtrlSetState($start, $GUI_DISABLE)
    GUICtrlSetState($stop, $GUI_ENABLE)
    GUICtrlSetData($Edit1, "")
    GUICtrlSetState($start, $GUI_DISABLE)
    $address = GUICtrlRead($url)
    $ping = Run("ping.exe -t " & GUICtrlRead($url), "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    While 1
        $line = StdoutRead($ping & @CRLF)
        If @error Then ExitLoop
        _GUICtrlEdit_AppendText($Edit1, $line)
        _GUICtrlEdit_Scroll($Edit1, $SB_SCROLLCARET)
        If GUIGetMsg() = $stop Then
            ProcessClose($ping)
            GUICtrlSetState($start, $GUI_ENABLE)
            GUICtrlSetState($stop, $GUI_DISABLE)
            ExitLoop
        EndIf
    WEnd
    GUICtrlSetState($start, $GUI_ENABLE)
    StdioClose($ping)
EndFunc   ;==>Pinger
Edited by Jos
1 person likes this

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Wow thanks, i never thought it's that simple it took me days trying to figure it out i tried AdlibRegister route but unsuccesful

thanks you're the best!

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