Creates a pipe and executes a command. Mode can be one of:
- "r" - The calling process can read the spawned command’s standard output via the returned stream. This is the default.
- "w" - The calling process can write to the spawned command’s standard input via the returned stream.
- "b" - Open in binary mode.
- "t" - Open in text mode.
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)