lua-users home
lua-l archive

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


On Aug 5, 2013, at 7:50 PM, Henrique Gogó <henriquegogo@gmail.com> wrote:

> fname = os.tmpname ()
> os.execute ("/bin/bash -c set > " .. fname)
> f = io.open (fname, "r")
> s = f:read ("*a")
> print (s)
> f:close ()  -- close it
> os.remove (fname)

A bit unrelated to the topic at hand, but for the record… 

Say one would like to invoke an external command to, say, identify all environment variables of a process… io.popen is your friend:

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

Usage example:

lua << \EOF
local aHandle = assert( io.popen( 'env' , 'r' ) )

for aLine in aHandle:lines() do
  print( aLine )
  print( ( 'key = %q value = %q' ):format( aLine:match( '^(.-)=(.-)$' ) ) )
end

EOF