Good evening! Through Runtime.exec , a certain Linux program is called that dynamically displays the result in this form (the numbers change with a frequency of 5-10 seconds):

enter image description here

This dynamic display is achieved by inserting text into the text entry area. That is, the text is inserted into the input field, and, when updated, is erased and inserted again. Then the text does not "move" up, but remains on one line.


Question: how can this text be considered by any method ( Scanner , System.in , etc.)?

    1 answer 1

    Runtime.exec returns you an object of the Process class. This object has a getOutputStream() method, which will return the desired stream to you. Most likely you will have to handle terminal commands that allow you to update the string dynamically.

    But it is better to use ProcessBuilder , not Runtime.exec . This class allows you to describe in detail exactly how to start the process: in what environment, at what point, etc.

    • But how can you use the OutputStream to read what the program writes in the input field? It seems to me that something similar to the InputStream needed. - Rostislav Dugin
    • @RostislavDugin as I wrote to you in the answer - you need to analyze the commands that the program sends to the standard output stream (but the command may not use the standard stream). What team are you running? - Mikhail Vaysman
    • I vnstat -l -i ens3 ( ens3 is the network interface, usually denoted as eth0) . Powered by Linux. - Rostislav Dugin