victorio
victorio

Reputation: 6646

What is the equivalent code of the CTRL+C task killing on windows?

On Windows 7, I have a Java Application, which can start other JAR-s (which are running in background).

In this Application, I have a button, which shoul represent the CTRL+C command for every other started (and still running) JAR-s. I have found this code, which should kill the task by PID (6272):

taskkill /F /PID 6272

But if I run this code on a command propmt, a lot of times it is just waiting, and than return false, so it cannot kill the program. Sometimes it can kill, sometimes it cannot.

I would need a command, which is similar to CTRL+C, because if you hit this CTRL+C, the actual process will end immediately, without waiting!

Could anyone help me please? Thank you!

Upvotes: 3

Views: 975

Answers (1)

Deepak Bhatia
Deepak Bhatia

Reputation: 6276

First of all why you need the command to fire from Java when you have the hold of Process object by which you launch a jar, you can simply use destroy(); to kill the process you have launched.

Process p = Runtime.getRuntime().exec( "bla bla bla");      
p.destroy();

And if you really need to do it manually from command prompt then you have to find the process id and kill it by using the command you have already mentioned, you can read more here kill process command line windows 7 and Microsoft Taskkill

Upvotes: 1

Related Questions