-7

I have a method called taskkill() written in java. I want to implement the cmd command taskkill in the selected field (as shown). I don't know how to apply this command in java. Please help.

    public static Timer taskkill() {

    TimerTask timerTask = new TimerTask() {

    @Override
    public void run() {             
      // TO APPLY CMD COMMAND [ TASKKILL /F /FI "WINDOWTITLE ne File1" /FI "WINDOWTITLE ne File2" ]
    }
};

Timer timer = new Timer("MyTimer");  //create a new Timer

timer.scheduleAtFixedRate(timerTask, 30, 10000);  //this line starts the timer at the same time its executed

return timer;
user2451844
  • 11
  • 1
  • 3
  • 1
    `Runtime.getRuntime().execute()` may be what you're after. – Michael Berry Jul 03 '14 at 12:26
  • possible duplicate of [TASKKILL command implementation using JAVA](http://stackoverflow.com/questions/24545819/taskkill-command-implementation-using-java) – avgvstvs Jul 03 '14 at 12:28
  • But how should I use "Runtime.getRuntime().execute()" to implement taskkill command. Please wrap the taskkill command in the said function. I shall be really thankful to you for the help. – user2451844 Jul 03 '14 at 14:36

1 Answers1

1

Have a look at Runtime.exec() which allows you to run arbitrary programs from the JVM (modulus relevant permissions of course).

Cheers,

Anders R. Bystrup
  • 15,729
  • 10
  • 59
  • 55