I am trying to run the below command from java and want to capture the output. The method is getting completed immediately without writing anything to the console.
Linux Command is repo forall -c 'echo pwd is;pwd;git status'
and the method is
public static String executeCommandWithOutput(String command) {
System.out.println("Running the command "+command);
StringBuffer output = new StringBuffer();
String line = "";
try {
Process process =Runtime.getRuntime().exec(command);
process.waitFor();
BufferedReader reader =
new BufferedReader(new InputStreamReader(process.getInputStream()));
while ((line = reader.readLine())!= null) {
output.append(line);
}
System.out.println("Content is "+output.toString());
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
return output.toString();
}
I tried redirecting the output to a file as well. Neither worked. Any thoughts??