Fflush(stdout) in L?


I am running an external process with system(). I don’t need any output. It looks like this:

printf("Running... ")
system("process_that_takes_long > /dev/null");

The problem is that “Running…” doesn’t get displayed until AFTER the completion of process_that_takes_long… I don;t have the issue if I don’t redirect the output of the process to /dev/null (but then I have garbage on display).

Is there a way to flush a message to stdout? I would use ‘fflush’ in C.

Thanks a lot,

Ok, I got it. There is an undocumented ‘flush’ function:

printf("Running... ")
system("process_that_takes_long > /dev/null");

Seems busted that we didn’t use the C/stdio compat name, we can fix that.

Your other option is to learn about fconfigure() which is like setbuf() on steriods.
You can learn about it by example or reading the fconfigure.n man page in the tcl/doc

fconfigure(stdout, buffering: “none”);

should also do what you want.

Ah, I see, this is a tcl/L rough edge. It turns out that tcl has a [flush $file] call. Since tcl/L calls can be mixed and since we use the same data structures where possible, the following do the same:

printf(“Hi there\n”);
#lang tcl
flush stdout
#lang L

There is a lot of useful functionality in tcl that we didn’t see the need to replicate. That may be the wrong answer, but it’s always worth wandering around the tcl/doc directory and looking at those functions.

Other than wrapping everything in C/stdio compat interfaces, dunno what to do. It’s true that knowing some tcl definitely makes you more productive in L. I tend to use L for systems stuff, like where I’d use perl or awk, and most of that stuff is there.

I guess I’d say be noisy and we’ll look at greasing the squeaky wheel :slight_smile:

BTW, there was a bug in notifications so we didn’t see this thread right away, we fixed it.

1 Like

Many thanks Larry, that’s very useful information indeed.

No problem, sorry about the delay.