os.execute
Lua function

os.execute

Summary

Executes an operating system command

Prototype

status = os.execute (command)



Description

Passes 'command' to the operating system shell for execution. Returns a status code.


status = os.execute ("dir") --> (directory listing whizzes by)


Here is a method of capturing the output to a file, and reading it in:


-- 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)



See Also ...

Topics

DOC_lua_base Lua base functions
DOC_lua_bc Lua bc (big number) functions
DOC_lua_bit Lua bit manipulation functions
DOC_lua_coroutines Lua coroutine functions
DOC_lua_debug Lua debug functions
DOC_lua_io Lua io functions
DOC_lua_math Lua math functions
DOC_lua_os Lua os functions
DOC_lua_package Lua package functions
DOC_lua_rex Lua PCRE regular expression functions
DOC_lua Lua script extensions
DOC_lua_string Lua string functions
DOC_lua_tables Lua table functions
DOC_lua_utils Lua utilities
DOC_scripting Scripting

Lua functions

LUA_os.clock os.clock (Amount of CPU time used)
LUA_os.date os.date (Formats a date/time string)
LUA_os.difftime os.difftime (Calculates a time difference in seconds)
LUA_os.exit os.exit (Attempts to terminate the process)
LUA_os.getenv os.getenv (Returns an operating system environment variable)
LUA_os.remove os.remove (Deletes a file)
LUA_os.rename os.rename (Renames a file)
LUA_os.setlocale os.setlocale (Sets the current locale to the supplied locale)
LUA_os.time os.time (Returns the current time or calculates the time in seconds from a table)
LUA_os.tmpname os.tmpname (Returns a name for a temporary file)

(Help topic: lua=os.execute)

DOC_contents Documentation contents page