I am trying to pass a variable from java code to batch file. The content of the batch file is-
@echo off
set rootFolder=%1
set logFolder_Dir=logs
set outputLogsFolder_LocalDir=%rootFolder%\%logFolder_Dir%
set filename=%2
adb shell setprop persist.log.tag V
adb logcat com.harman.prometheusnav > %filename%.txt
pause
I need to pass the value of rootFolder and filename from java code to batch file. Java code to run and close the batch file is -
public static void main(String[] args) throws InterruptedException, IOException {
ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "logs.bat");
File dir = new File("C:\\WORKPLACE\\NavSDK\\Prometheus\\Automation\\promta\\src\\test\\resources");
pb.directory(dir);
Process p = pb.start();
Runtime rt = Runtime.getRuntime();
rt.exec("taskkill /F /IM adb.exe /T");
Is there any other idea to update the batch variable?
CodePudding user response:
According to the documentation for ProcessBuilder, you should simply just add your arguments to the end of the list.
public static void main(String[] args) throws InterruptedException, IOException {
ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "logs.bat", "C:\RootFoolder", "FileName");
File dir = new File("C:\\WORKPLACE\\NavSDK\\Prometheus\\Automation\\promta\\src\\test\\resources");
pb.directory(dir);
Process p = pb.start();