io.popen

Creates a pipe and executes a command

Prototype

f = io.popen (command, mode)

Description

Creates a pipe and executes a command. Mode can be one of: However io.popen is not supported under the version compiled into MUSHclient, so don't get too excited. :)

This is an example of using popen under the Linux Lua executable:

 f = assert (io.popen ("ls -l"))
  
 for line in f:lines() do
   print(line)
 end -- for loop
   
 f:close()
An alternative to using pipes, if you want to capture operating system output, is to redirect command output to a temporary file, like this:

-- get a temporary file name
n = os.tmpname ()

-- execute a command
os.execute ("dir > " .. n)

-- display output
for line in io.lines (n) do
  print (line)
end

-- remove temporary file
os.remove (n)

Lua functions

Topics