lua-users home
lua-l archive

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


On Thu, 21 Aug 2008 12:44:58 -0700
"Wesley Smith" <wesley.hoke@gmail.com> wrote:

> Hi,
> Is there a pure lua way to redirect stdout back into Lua?  For example
> if I have the script:
> 
> os.execute("pwd")
> 
> Can I get the result of calling pwd back as a string in Lua?  If
> there's not a pure Lua way, are there any modules out there that
> redirect stdout?

If you have built your Lua appropriately, and on a platform that can
support it, you can use io.popen:

	http://www.lua.org/manual/5.1/manual.html#pdf-io.popen

If not, and you don't want to have to resort to C, you'll have to get
your system's shell to redirect the output to a file, and then read it
in.

B.