[texworks] line buffered output

Charlie Sharpsteen chuck at sharpsteen.net
Tue Nov 22 05:11:43 CET 2011


On Mon, Nov 21, 2011 at 2:18 PM, Charlie Sharpsteen
<chuck at sharpsteen.net> wrote:
> On Sunday, November 20, 2011, Arno Trautmann <Arno.Trautmann at gmx.de> wrote:
>> Hi all,
>>
>> following Tako's answer to a question on the LuaTeX list¹, it seems that
>> TeXworks' terminal output is block-buffered. That is suboptimal in some
>> special cases, as the one I'm describing in that mail. Is it possible to
>> change this in TeXworks?
>>
>> To explain my request: Look at the following plain LuaTeX example:
>>
>> \let\n\relax
>> \directlua{
>>  delay = 1.0
>>  texio.write_nl("first comment\n")
>>  os.sleep (delay)
>>  texio.write("second comment\n")
>>  os.sleep (delay)
>> }
>> \bye
>>
>> and have a look at the terminal output in TeXworks, in comparison to
>> compiling a normal terminal. The two comments should be output with a time
>> delay between them, which does not happen with TeXworks (at least not with
>> r.944 on x86_64 Arch Linux)
>>
>> Cheers
>> Arno
>>
>> ¹http://tug.org/pipermail/luatex/2011-November/003352.html
>
> I did some quick poking by setting the QProcess used to run typesetting
> tools to use an `Unbuffered` stream. However, the log window still shows the
> version string when LuaTeX starts up, then waits 2 seconds and shows the
> rest of the output in one chunk after LuaTeX has finished.
> I think the problem lies with LuaTeX as the behavior of just about every C
> library is to block buffer output _unless_ the program is communicating with
> a TTY or the programmer called something like `setbuf(stdout, _IOLBUF)` or
> uses `fflush` at appropriate locations to flush stdout to the calling
> process. So, after my test it looks like the log is getting block buffered
> inside LuaTeX before it even crosses over to TeXworks.
> Taco could provide a definite answer as to how stdout buffering is handled
> on the LuaTeX side.
> -Charlie

Just tried again with a simple Node.js script:


#!/usr/bin/env node

var spawn = require('child_process').spawn;

luatex = spawn('luatex', ['logging.tex']);

luatex.stdout.on('data', function(data) {
  console.log(data );
});

luatex.stderr.on('data', function(data) {
  console.log(data );
});


Where the file 'logging.tex' contains your LuaTeX example. The results
are the same: Node prints out the LuaTeX startup banner, then waits
two seconds and dumps the rest of the output all at once.

Since Node.js fires callbacks as soon as data enters the stream, it is
looking like LuaTeX is block buffering its output when not connected
to a terminal.

-Charlie



More information about the texworks mailing list