Sign in to follow this  
Followers 0
Terenz

Abort command prompt command

5 posts in this topic

#1 ·  Posted (edited)

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

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

Cool example but not work for me, i have try it


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

 

Share this post


Link to post
Share on other sites

Cool example but not work for me, i have try it

But it does not work for your case

...

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


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

If is possible i prefer to run the process only one time, if not my last chance is respawn cmd everytime.


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

 

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