mike bayko
mike bayko

Reputation: 385

How could I start/display a file in lua, like the batch command "start"?

I have looked into opening/starting files in lua, however every single article is giving me functions like dofile() that returns/runs the file status/contents, instead of actually opening/starting the file. In my scenario I have a .hta file that I am trying to start through lua, what I am technically wondering is if lua has a function kind of like the batch command "start", that starts a file, if not is there any method to send commands to a console from a lua file? If anyone could help me out I would really appreciate it.

Upvotes: 1

Views: 775

Answers (1)

britzl
britzl

Reputation: 10242

What you are looking for is os.execute(). It allows you to run a command in an operating system shell:

local code = os.execute("ls -la")
if code ~= 0 then
    print("Something when wrong while running command")
end

If you also want to capture the output from the executed command and use it in your Lua code you can use io.popen():

local f = assert(io.popen("ls -la", 'r'))
local output = assert(f:read('*a'))
f:close()
print(output)

Note that io.popen() isn't available on all systems.

Upvotes: 3

Related Questions