Some programs produce output to bash in a way that the user experience like strings that changes values rather than rows printed(bash scrolls down to be able to show all the changing output). What is this phenomena called? How is it achieved in e.g a java program or a bash script. How can the output be parsed? Is it just printing new lines but using some special function?
top is one program that uses this "phenomena" of outputting data
Okey cursors are used.
Then how can i parse them in java? I tried this code but it does not print anything
public static void exeTest(String [] args) throws IOException{
if (args.length <= 0) {
System.out.println("empty command");
return;
}
Process process = new ProcessBuilder(args).start();
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
System.out.printf("Output of running %s is:",
Arrays.toString(args));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
Thanks for all good answers, im now more familiar at this topic even thou I still cant parse a program output like the one from top in java. Ill close this question and do more research about how to parse this in java. Then I may start another more specific one about just parsing the output in java.