Fflush(stdout) in L?


#1

Hi,

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");
puts("done.);

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,
Lyderic


#2

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

printf("Running... ")
flush(stdout);
system("process_that_takes_long > /dev/null");
puts("done.);

#3

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
directory.

fconfigure(stdout, buffering: “none”);

should also do what you want.


#4

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
flush(stdout);

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.


#5

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


#6

No problem, sorry about the delay.