lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


>From lua-l@tecgraf.puc-rio.br Tue Jul 20 01:02:31 1999
>From: Pablo Saldo <ec4pas@super.furg.br>

>How can I catch the outputs from stderror and stdout in Lua? I mean
>redirecting them to a variable or such a thing.

You might redefine 'write' to save all output into a variable.
Something like

  OUT=""

  function write(...)
	  foreachi(arg, function (i,v) OUT=OUT..v end 
  end

Not the fastest code in the world, but it works.
For a faster solution, you could store in OUT a table of strings.
Otherwise, I guess you'd have to change liolib.c.
--lhf