Jump to content

Sending control-c to a hidden cmd window


Recommended Posts

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
Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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...