Vishal Jagtap
Vishal Jagtap

Reputation: 896

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

Upvotes: 0

Views: 7952

Answers (1)

ManojP
ManojP

Reputation: 6248

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.

Upvotes: 3

Related Questions