2

My question is how can i can exit chrome using java please answer with a imports and package im a beginner :)

i tried: but i know that exec(String command) gets a a specified system command so its wrong there is another way ?

package com.tutorialspoint;


public class ProcessDemo  {

   public static void main(String[] args) {

       String url = "https://www.youtube.com/watch?v=Ei3Vymb_lFM&list=PLqKCUR6vbEfxGeSCePPlk7hH-mpIdqlpg&index=1";
   try {
   // create a new process
   System.out.println("Creating Process...");
   Process p = Runtime.getRuntime().exec(url);

   // wait 10 seconds
   System.out.println("Waiting...");
   Thread.sleep(10000);

   // kill the process
   p.destroy();
   System.out.println("Process destroyed.");

   } catch (Exception ex) {
   ex.printStackTrace();
   }

   }
}

the massage i got is Creating Process... java.io.IOException: Cannot run program "https://www.youtube.com/watch?v=Ei3Vymb_lFM&list=PLqKCUR6vbEfxGeSCePPlk7hH-mpIdqlpg&index=1": CreateProcess error=2, The system cannot find the file specified at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048) at java.lang.Runtime.exec(Runtime.java:620) at java.lang.Runtime.exec(Runtime.java:450) at java.lang.Runtime.exec(Runtime.java:347) at com.tutorialspoint.ProcessDemo.main(ProcessDemo.java:14) at Browser.main(Browser.java:39) Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified at java.lang.ProcessImpl.create(Native Method) at java.lang.ProcessImpl.(ProcessImpl.java:386) at java.lang.ProcessImpl.start(ProcessImpl.java:137) at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029) ... 5 more

metrix x
  • 21
  • 3
  • Please describe what happens when you invoke `destroy()` (edit the question, don't add a comment). –  Jan 12 '17 at 22:11

1 Answers1

0

You can have a look at this discussion : how to run a command at terminal from java program?

For killing chrome you can use pkill "Google Chrome"

Community
  • 1
  • 1
Antaka
  • 27
  • 2
  • 4
  • Your error is refering to not being able to create the process . Have a look here : http://stackoverflow.com/questions/26104538/how-to-open-a-url-in-firefox-chrome-from-command-line-in-pop-up-mode – Antaka Jan 14 '17 at 09:13