-1

i want to execute the following command using a java program. "java -jar Demo.jar readExcelDemo.Hvd"

public class ExcelDriver {
    public static void main(String[] args) throws IOException {
        Runtime runTime = Runtime.getRuntime();
        Process process = runTime.exec("cmd","/c", "cmd.exe","java -jar Demo readExcelDemo.Hvd");

            }
}
Venkat Kondeti
  • 81
  • 1
  • 12

3 Answers3

0

create a .bat or .cmd file with content java -jar Demo readExcelDemo.Hvd

change your code to

public class ExcelDriver {
public static void main(String[] args) throws IOException {
    Runtime runTime = Runtime.getRuntime();
    Process process = runTime.exec("cmd","/c", "myfile.cmd");

        }

}

0

Try this:

Runtime runTime = Runtime.getRuntime();
Process process = runTime.exec("java -jar Demo.jar readExcelDemo.Hvd");

If above code is not okay, try this:

Runtime runTime = Runtime.getRuntime();
Process process = runTime.exec("cmd.exe /c start java -jar Demo.jar readExcelDemo.Hvd");

If you want to watch cmd, you can use below code. It will immediately close because of the /c flag.

 Process p = runTime.exec("cmd.exe /c start cmd /k java -jar Demo.jar readExcelDemo.Hvd");
Ye Win
  • 2,020
  • 14
  • 21
-1

You can just call:

Runtime.getRuntime().exec(command);
Dara
  • 107
  • 1
  • 7