'What changes need to do for my Java Code to execute .bat and get output
I am trying to fetch Output from .bat file running from java. I am getting only first line and rest all empty.
my Java code:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Test4 {
public static void main(String[] args) throws IOException {
String lineInner = null;
try {
String line = null;
String cmd = "F:\\Softwares\\Pega\\117090_Pega8.62_StudioFile\\scripts\\migrate.bat";
Runtime r = Runtime.getRuntime();
Process pr = r.exec(cmd);
BufferedReader stdInput = new BufferedReader(
new InputStreamReader(pr.getInputStream()));
String s;
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
lineInner = s;
lineInner = line + "\n" + lineInner;
}
} catch (Exception err) {
err.printStackTrace();
}
}
}
Output:
Invoke our ant script, passing in the arguments as collected
While running directly .bat file I am getting long response as below.
Invoke our ant script, passing in the arguments as collected Buildfile: F:\Softwares\Pega\117090_Pega8.62_StudioFile\scripts\migrateSystem.xml
CollectProperties: [pega:propertyparser] Reading Properties from: F:\Softwares\Pega\117090_Pega8.62_StudioFile\scripts/migrateSystem.properties [echo] Using logging configuration from: F:\Softwares\Pega\117090_Pega8.62_StudioFile\scripts/config/deploylogging.properties [echo] *** JVM Arguments -Xmx4g -XX:+HeapDumpOnOutOfMemoryError -Djava.util.logging.config.file='F:\Softwares\Pega\117090_Pega8.62_StudioFile\scripts/config/deploylogging.properties' *** [mkdir] Created dir: F:\Pega\temp\MigrateTemp-16-February-2022-18.09.53 [echo] Using temporary directory F:/Pega/temp/MigrateTemp-16-February-2022-18.09.53
VerifyProperties: [echo] Perform pre-upgrade tasks: true [echo] Perform data schema tables movement: false [pega:getdataadminsystemsetting] No DASS setting found in database with Owning ruleset 'Pega-Engine' and Setting Purpose 'ZeroDowntimeUpgradeInProgress'
Setup:
Generate Table Lists: [echo] SchemaAssignmentUtility methods: move,movetorules [echo] SchemaAssignmentUtility output files: F:/Pega/temp/MigrateTemp-16-February-2022-18.09.53/tables.txt,F:/Pega/temp/MigrateTemp-16-February-2022-18.09.53/datatorulestables.txt [java] Platform = postgres [java] skipTruncates value = [java] moveCompelteSchema value = null [java] Filename:F:/Pega/temp/MigrateTemp-16-February-2022-18.09.53/tables.txt,F:/Pega/temp/MigrateTemp-16-February-2022-18.09.53/datatorulestables.txt [java] Executing method 'GET_MOVE' -- writing output to 'F:/Pega/temp/MigrateTemp-16-February-2022-18.09.53/tables.txt' [java] Executing method 'GET_MOVE_TO_RULES' -- writing output to 'F:/Pega/temp/MigrateTemp-16-February-2022-18.09.53/datatorulestables.txt'
Solution 1:[1]
Looks like your OS is MS Windows. You have to prefix your command with "cmd /c ", so Windows knows which command processor to use.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Donat |
