Jump to content

StdInWrite


Cheez
 Share

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 
            Draw_Text($line)
            $line = ""
        EndIf
        If $ExitKeyFlag = 1 Then 
            ;StdioClose($Run_Handle)
            ;ProcessWaitClose($Run_Handle, 2000)
        EndIf
    Wend

EndFunc

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.

Link to comment
Share on other sites

  • 1 year later...

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

http://www.cs.tut.fi/~jkorpela/chars/c0.html

*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

Link to comment
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.

http://www.latenighthacking.com/projects/2003/sendSignal/

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

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