Jump to content
Sign in to follow this  


Recommended Posts


I'm writing something that can interact with DOS commands, the problem is if the DOS command gets into an infinite loop (eg: ping -t google.com), there's no way to escape the sequence.

Normally one would simply hit Ctrl + C and it would print a summary, though sending any variation of "Control-C" & @CRLF & "^C" via StdInWrite() only prevents the information from being sent through the pipe.

Func Command($Command)
    Local $Run_Handle, $out, $line = ""
    $Run_Handle = Run(@ComSpec & " /c " & $Command, @TempDir, @SW_HIDE, $STDIN_CHILD + $STDERR_CHILD + $STDOUT_CHILD) 

    While 1 
        $out = StdoutRead($Run_Handle)
        If @error Then ExitLoop 
        $line &= $out
        If StringInStr($out, @LF) <> 0 Then 
            $line = ""
        If $ExitKeyFlag = 1 Then 
            ;ProcessWaitClose($Run_Handle, 2000)


Using StdioClose() merely closes the pipes, and the command appears to still be working (through taskman) ProcessClose() also appears to be ineffectual in closing the child.

Share this post

Link to post
Share on other sites

Good Question. I am having the same issue. How to send Ctrl+c via StdinWrite?? :x

Share this post

Link to post
Share on other sites

Ctrl-C ist the control character ETX (0x03). Send it with Chr(3) :x


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post

Link to post
Share on other sites

I have a help desk software that I made for our support staff. One of the things required is the output of the dos ping command so I had to use ping -t, but as you found when you're reading the output it's difficult to stop.

Unfortunately Chr(3) or other forms do not send the term signal.


I downloaded the sendsignal.exe, this is like send a break, not a term. I interrupt the function and run the signal term (I had to run it in the child pid directly, not what run had returned). When the function gets interrupted and I run sendsignal I set another flag to have the loop check the output for "Control-Break" and when it does it dumps out of the loop and closes ping. Gives the exact output one would be looking for.

I was a little worried but it works flawless.

Posted Image

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