Jump to content

How to send CTRL+C to a process


Recommended Posts

Hello,

I want to send a CTRL+C signal to a process. This process doesn't have a window. It is just an executable.

I identify the process that is running using this code, but I want to send a control+c. If I do a ProcessClose the process doesn't save its data correctly.

This is what I am using to find the process:

$list = ProcessList("cp_detect.exe")

for $i = 1 to $list[0][0]

msgbox(0, $list[$i][0], $list[$i][1])

ProcessClose("cp_detect.exe")

next

Any idea?

Thanks

tony

Link to comment
Share on other sites

Hello,

I want to send a CTRL+C signal to a process. This process doesn't have a window. It is just an executable.

I identify the process that is running using this code, but I want to send a control+c. If I do a ProcessClose the process doesn't save its data correctly.

This is what I am using to find the process:

$list = ProcessList("cp_detect.exe")

for $i = 1 to $list[0][0]

msgbox(0, $list[$i][0], $list[$i][1])

ProcessClose("cp_detect.exe")

next

Any idea?

Thanks

tony

In normal (not scripted) operation, how do you close it while saving data?

Is it a console app (running in a "DOS box" similar to Telnet.exe)?

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Send just presses keys. It doesn't require a target. You are stupid on this one. :)

It is a process created from the command line using a perl script. The process is spawnd by the perl script. Once the main script returns, this child process remains active.

If the program (cp_detect.exe) is run from the command line I can manually do CRTL+C and everythnig works fine. I am trying to automate this by running from perl using a system() function. Another program needs to be run as a parent from the same script. Once this other program is done, I need to close my cp_detect.exe.

tony

Link to comment
Share on other sites

Hello,

I want to send a CTRL+C signal to a process. This process doesn't have a window. It is just an executable.

I identify the process that is running using this code, but I want to send a control+c. If I do a ProcessClose the process doesn't save its data correctly.

This is what I am using to find the process:

$list = ProcessList("cp_detect.exe")

for $i = 1 to $list[0][0]

msgbox(0, $list[$i][0], $list[$i][1])

ProcessClose("cp_detect.exe")

next

Any idea?

Thanks

tony

This is an option

CODE
;//Alt+Keys Monitor:

Func _KeysMonitor()

$dll = DllOpen("user32.dll")

;//Alt+C Switch

If _IsPressed('12', $dll) And _IsPressed('43', $dll) Then

DllClose($dll)

_yourfunction()

EndIf

DllClose($dll)

EndFunc ;==>_KeysMonitor

Cheers Ant.. :)
Link to comment
Share on other sites

yourfunction()
func yourfunction()
msgbox(0,"Hi There", "I'm a messagebox called by yourfunction()")
endfunc

Check out AutoIt 1-2-3.

That should walk you through the basics of the language, and get you on your feet to the point where the Help File can answer your questions a lot more quickly than the forum. Good luck!

Link to comment
Share on other sites

yourfunction()
func yourfunction()
msgbox(0,"Hi There", "I'm a messagebox called by yourfunction()")
endfunc

Check out AutoIt 1-2-3.

That should walk you through the basics of the language, and get you on your feet to the point where the Help File can answer your questions a lot more quickly than the forum. Good luck!

That was a good reply by way of explaination func yourfunction() is a subroutine of the code which continually looks for the user pressing Ctrl+C so whatever you want Ctrl+C to do is what you put in the routine called. The nameing yourfunction() was simply for explaination purposes. You can call it what ever you want many coders use the Func _yourroutine() "note the '_'" for reasons better understood as your skills with this language develop. Dont forget that you can pass values to the sub routine by including them in the call for example yourfunc(6,12) on the subroutine side the values to be passed are given a variable Func yourfunction($value1, $value2) in this case the $value1 variable is 6 and the $value2 variable is 12. Variables can be Local, Global etc. Good luck with your project Ant..
Link to comment
Share on other sites

Can the perl script send anything to the Stdin of cp_detect.exe ? If so, before terminating the perl script, you can send Ctrl+C to all the child processes.

If not you can call your script, which will call cp_detect.exe using run() and hooking up to the Stdin of the process, then either:

-wait for the parent process (the perl script) to end, then send Ctrl+C to the process's stdin

-Wait for some other external process to try and close the Autoit script, then send Ctrl+C to the process.

Are you reading any information from Stdout in the process in perl?

FYI CTRL+C is ACSII code 03

Edited by TurionAltec
Link to comment
Share on other sites

I figured out how to accomplish that. I send a CTRL+C to the cmd.exe that is open and that does the trick.

her is the code that seems to work:

$list = ProcessList("cmd.exe")

for $i = 1 to $list[0][0]

WinActivate("cmd.exe", "") ;

Send ("^c")

next

Thanks all for your help.

tony

Link to comment
Share on other sites

I figured out how to accomplish that. I send a CTRL+C to the cmd.exe that is open and that does the trick.

her is the code that seems to work:

$list = ProcessList("cmd.exe")

for $i = 1 to $list[0][0]

WinActivate("cmd.exe", "") ;

Send ("^c")

next

Thanks all for your help.

tony

A bit late to make a suggestion maybe but here goes.

Waiting for "cmd.exe" could be a problem because there is no guarantee that there is only one running. If you include in the start up somehow a command

"Title someunique19876name"

then the command window you are interested in will have a unique name and you can Winactivate the correct window.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

hey i hav a similar problem

i am automating my ping process but the problem is that i run my ping like this

CODE
$cmd = Run(@ComSpec & " /c ping " & $ipadd &" -t",@AppDataDir,@SW_HIDE, 0x2 + 0x4 + 0x1 )

now when the program exits the ping process still continues which should no happen

it happens because i have given "-t" parameter. i also need it because i want it to run till my program is running

so how can i close this process????

ProcessClose() Does Not word

Link to comment
Share on other sites

hey i hav a similar problem

i am automating my ping process but the problem is that i run my ping like this

$cmd = Run(@ComSpec & " /c ping " & $ipadd &" -t",@AppDataDir,@SW_HIDE,  0x2 + 0x4 + 0x1 )

now when the program exits the ping process still continues which should no happen

it happens because i have given "-t" parameter. i also need it because i want it to run till my program is running

so how can i close this process????

ProcessClose() Does Not word

What process did you try to close?

ProcessClose($cmd) should work. Oops.

ProcessClose("ping.exe") should work.

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...