I am writing a GTK+ frontend program that shreds files. The program shred
from GNU Coreutils is the backend. The programming language is C.
So, I have a progress bar that show how much of the shredding is finished. But, in order to give the user accurate data on how much is shredded, the output of shred must be analyzed.
So far I have tried g_spawn_command_line_async
, but I am not able to send the output of shred to a file.
The easiest solution is using unix redirection. You can call system("shred -v file_to_shred > somefile.txt")
and the output will be redirect to the file. You can then read from the file using POSIX read or some other file reading method. Run the system()
call in a seperate thread, and the just incremently check the file in the main thread. You could use POSIX sleep()
to check the file at some interval, say, every half second. However, never use sleep on the GUI thread, as this will freeze the UI.