Jump to content

Abort command prompt command


Terenz
 Share

Recommended Posts

Hello :D

I don't have found a way to abort a command using prompt command in autoit like CTRL+C in a CMD windows

My script:

#include <Constants.au3>

HotKeySet("{ESC}", "StopCommand")
HotKeySet("1", "ReDoCommand")

Local $pid

$pid = Run(@ComSpec & " /k ", "", @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD)
StdinWrite($pid, "ping -t www.google.com" & @CRLF)

While 1
    $msg = StdoutRead($pid)
    If $msg <> "" Then ConsoleWrite($msg)
    Sleep(50)
WEnd

Func ReDoCommand()
    StdinWrite($pid, "ping -t google.com" & @CRLF)
EndFunc

Func StopCommand()
    ConsoleWrite("-STOP HERE" & @CRLF)
;~  $hCmd = WinGetHandle("C:\WINDOWS\system32\cmd.exe")
;~  ControlSend($hCmd, "", "", "^c")
EndFunc

ControlSend seems don't do nothing :(

P.S. I don't want to use ProcessClose or StdioClose, i want to have one CMD process and give the command to that process and not run-open-close-run-open-close etc.

Suggestion?

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Link to comment
Share on other sites

Hi,

You need to send a SIGNAL to the process, in this case SIGINT (in the point of view of UNIX).

There is the SendConsoleCtrlHandler function, an example is available >here. But it does not work for your case and I'm not able to tell you why without digging.

 

I suggest you to close the process and start a new one, it's a simple command prompt.

 

Br, FireFox.

Edited by FireFox
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...