0

I have jar file(selenium-server-standalone-2.44.0.jar) kept at c:\ drive. I need to navigate to C drive and execute below command through java

java -jar selenium-server-standalone-2.44.0.jar -role hub

Vishal Jagtap
  • 896
  • 11
  • 16
  • `Runtime.exec("cd C:\"); Runtime.exec("java -jar selenium-server-standalone-2.44.0.jar -role hub")` – nattyddubbs Jun 29 '15 at 14:24
  • `Runtime` will definitely work. If you want more control (like the ability to handle standard in/out), [ProcessBuilder](https://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html) will give you more. [Here's](http://stackoverflow.com/a/6856659/2494555) some info contrasting the two. – blazetopher Jun 29 '15 at 14:34

1 Answers1

3

You can try below code

 Process process  = Runtime.getRuntime().exec("cmd /c start cmd.exe /K java -jar selenium-server-standalone-2.44.0.jar -role hub");

However this will run executable jar from your current directory, where you .class file exist.

ManojP
  • 6,113
  • 2
  • 37
  • 49