0

I'm sure some people are familiar with the concept. You run a command at the CLI and as it progresses, the one line in front of you updates with a percentage. Under the bonnet, before each line is printed, it clears the current line, so instead of 100 lines of progress updates, you just have one line which updates until it hits 100%.

I want to make an app that will echo this information out into an embeded diaplay window. I'm fairly new to Java and I'd like my app to run a Windows command (sfc /scannow to be exact), display the output to the user on-the-fly and then once complete, I want to analyse the log file and give a readable conclusion to the user.

Is there some kind of library or special way of going about doing this so that when the line is "updated" in the console window, I can simply overwrite the current line in my display window?

thefuzzy0ne
  • 479
  • 3
  • 10
  • https://stackoverflow.com/questions/55560959/is-there-a-way-to-output-ansi-escape-sequences-using-low-level-output/55566065#55566065. It will be writing direct to the window not to StdOut. – Noodles May 11 '19 at 19:26
  • I'm sorry, but I have absolutely no idea how this answers my question. – thefuzzy0ne May 13 '19 at 13:15
  • Well perhaps you should study your topic. It a direct answer on your topic area. Study it. It says how to write to consoles in a specific location. – Noodles May 13 '19 at 18:09
  • I don't understand how to access the `SetConsoleCursorPosition()` function. My question really was how to establish when a line has been updated as opposed to just added, but I think @kutschkem has answered that. Thanks for your input. – thefuzzy0ne May 14 '19 at 22:55

1 Answers1

1

The line is probably updated by the program writing \r control character (carriage return) to stdout. It is the task of the receiving application to handle this. The normal terminal handles this by setting the cursor to the start of the line. Your program can intercept this character and also treat it by resetting the line.

kutschkem
  • 7,826
  • 3
  • 21
  • 56