Search code examples
javacommand-linecmdexecselenium-grid

How to execute cmd commands through java


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


Solution

  • 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.