Trevor Hickey Trevor Hickey - 2 months ago 8
Linux Question

is there a linux program to continuously run another program without flicker?

I would like to run a command line program again and again inside an infinite loop.

The program will occasionally output different data.

Whenever the new data is output, I would like the previous data to be overwritten.

Example:

The following program will output the time of day.

#include <stdio.h>
#include <time.h>

int main (){
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
printf ( "Current local time and date: %s", asctime (timeinfo) );
}


The naive approach would be the following:

while true; do ./main; clear; done


Of course, this will clear the screen every run, and cause a flicker.

enter image description here

I could certainly pipe it into a custom program that only refreshes output on change,

but I was hoping to find a solution using standard linux commands

(or Bash language features).

Answer

If you have the command watch available, you could use that. Simply type

watch ls