Andreas Rozek      

LuaJava_01 - intermixed access to stdin/stdout

"LuaJava_01" experiments with alternating access to stdin (or stdout) from within Lua and Java. Depending on the actual environment the results may not be as desired...

Please, also consider my "Hints for Reading" and the "List of Recent Changes"!
(Problems displaying this page? Ugly graphics? Please, click here)

LuaJava_01

The script itself is extremely simple and should not require any further explanation. Its invocation has the form
 

  java luna.LuaJava LuaJava_01.lua

After an invocation from the (Windows) console, "LuaJava_01" produces:

  LuaJava_01 - what happens with intermixed accesses to stdout and stderr?

    1:    Java -> stdout
    2:     Lua -> stdout
    3: LuaJava -> stdout
    4:    Java -> stderr
    5:     Lua -> stderr
    6: LuaJava -> stderr
  done

as one might expect.

But when invoked from within an environment which captures the output of external programs (e.g., the author uses the TextPad editor to develop and test any scripts and programs - including Lua/LuaJava scripts) the "LuaJava_01" may output:

  LuaJava_01 - what happens with intermixed accesses to stdout and stderr?

    1:    Java -> stdout
    3: LuaJava -> stdout
    4:    Java -> stderr
    6: LuaJava -> stderr
  done

    2:     Lua -> stdout
    5:     Lua -> stderr

i.e., output written using functions from Lua's io library is delayed.

The reason for this behaviour is unclear to the author - it might just be wise not to mix the different methods of accessing stdout/stderr within the same script...

Source Code

The source code of this script is publically available:

Disclaimer

Please, also consider the author's Disclaimer!


http://www.Andreas-Rozek.de/LuaJava/Acquainting/LuaJava_01_en.html   (last Modification: 14.11.2004)