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

1
  • Please describe what happens when you invoke destroy() (edit the question, don't add a comment). Commented Jan 12, 2017 at 22:11

1 Answer 1

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"

Sign up to request clarification or add additional context in comments.

1 Comment

Your error is refering to not being able to create the process . Have a look here : stackoverflow.com/questions/26104538/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.