Fprintf() looks not 'updating/flushing' the output file

The below script is started from octave whne ‘xclock’ is running:
cklog.m (1.2 KB)
and script will exit when ‘xclock’ is shutdown.
But the output file “log_file.txt” (in ~/bin) does not appear before fclose(fid) used.

octave:1> cklog
Logging system behavior (temp&cpufreq)
RUNNING...
warning: strread is obsolete; use textscan instead
RUNNING...
RUNNING...
RUNNING...
RUNNING...
done!

Using command:

tail -f log_file.txt
would not give any results before the fclose(fid) appears…

Can I somehow make it write to the file more often so that I can follow the results with the
tail command?

“help fflush”

See also this note in the docstring of fopen:

Compatibility Note: Octave opens files using buffered I/O. Small writes are accumulated
until an internal buffer is filled, and then everything is written in a single
operation. This is very efficient and improves performance. matlab, however, opens
files using flushed I/O where every write operation is immediately performed. If the
write operation must be performed immediately after data has been written then the
write should be followed by a call to fflush to flush the internal buffer.

Looks like found…

octave:4> help flush
error: help: 'flush' not found
octave:5> help *flush
error: help: '*flush' not found
octave:6> help fflush
'fflush' is a built-in function from the file libinterp/corefcn/file-io.cc

Can the help work with the ‘*’ or ‘?’ somehow also?

Looks like the --gui -mode help is better… then I guess no way but to change using gui mode.

The lookfor command might be efficient enough though:

>> lookfor flush
fflush              Flush output to file descriptor FID.

Please, keep this thread on topic. If you have a new question, open a new thread.

octave:1> help fflush
'fflush' is a built-in function from the file libinterp/corefcn/file-io.cc

 -- fflush (FID)
     Flush output to file descriptor FID.

     'fflush' returns 0 on success and an OS dependent error value (-1
     on Unix) on error.

     Programming Note: Flushing is useful for ensuring that all pending
     output makes it to the screen before some other event occurs.  For
     example, it is always a good idea to flush the standard output
     stream before calling 'input'.

     See also: fopen, fclose.

Additional help for built-in functions and operators is
available in the online version of the manual.  Use the command
'doc <topic>' to search the manual index.

Help and information about Octave is also available on the WWW
at https://www.octave.org and via the help@octave.org
mailing list.
octave:2>