Wednesday, July 16, 2014

Executing batch file through Java

Batch file has to perform below actions.

1. Change the directory for a given path
2. start the node sever
3. Exit the command window

>cd D:\nodev0.18
>node app.js console
>exit

FileName: Myfile.bat
Batch file defined with variable arguments like below.

cd %1
%2 app.js console
exit

Java code for invocation:
String executePath = "cmd /c start Myfile.bat"
   Runtime.getRuntime().exec(executePath);

No comments:

Post a Comment