lua-users home
lua-l archive

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


It was thus said that the Great Petite Abeille once stated:
> 
> 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
> 

  I have a Lua module [1] that populates a table with all the current evironment
variables.  No external program required.

  -spc

[1]	https://github.com/spc476/lua-conmanorg/blob/master/src/env.c