I have a java project which executes a batch file. I would like to know if it is possible to change a normal java project to a spring boot project. If it is, can i know how do i roughly go about doing it?
I have read what is spring boot. However i am totally confused as to how do i apply that into this task of a java class executing a batch file.
Here are my codes:
RunBatchMain.java
public static void main(String args[])
{
//Run batch file using java
String filePath = "C:/Users/attsuap1/Desktop/test.bat";
try {
Process p = Runtime.getRuntime().exec(filePath);
} catch (Exception e) {
e.printStackTrace();
}
}
GetResponseMain.java
public static void main(String args[])
{
String filePath = "C:/Users/attsuap1/Desktop/test.bat";
try {
Process p = Runtime.getRuntime().exec(filePath);
p.waitFor();
InputStream in = p.getInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int c = -1;
while((c = in.read()) != -1){
baos.write(c);
}
String response = new String(baos.toByteArray());
System.out.println("Response From Batch File : "+response);
int exitVal = p.waitFor();
System.out.println("ExitValue: " + exitVal);
} catch (Exception e) {
e.printStackTrace();
}
}
Someone please help me. Thank you so much.
