W
W
waltaki2020-03-25 13:11:02
linux
waltaki, 2020-03-25 13:11:02

How to redirect output to a file?

There is a program that works as interactive (tty, or pty). In fact, it works like a base top.

prog > up.info

As a result, the file is filled with data

data414
data654
data342

and I need new data to be written over the old ones (but so that there is no moment when the file is empty), as it happens in stdout - when you use this program in the terminal.
data342

Is it possible to implement this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Saboteur, 2020-03-25
@saboteur_kiev

For top I would do this
topfile.sh

while true; do
 top -b -n 1 > top.log
 sleep 2
done

and ran ./topfile.sh &
If your program does not know how to work in batch mode, then it will be difficult.
You can write a script that starts a program in the background with a redirect, kills it with kill, add a sleep and wrap it in a loop.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question