1

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.

mike bayko
  • 375
  • 5
  • 20
  • 3
    I don't know what lua is. But hta are run by mshta.exe. so do `mshta c:\folder\file.hta`. According to your language you use `os.execute ([command])` - https://www.lua.org/manual/5.3/manual.html#6.9 –  Dec 07 '16 at 00:43
  • 2
    `os.execute[["c:\path\to\your\file.hta"]]` is the simplest method. – Egor Skriptunoff Dec 07 '16 at 05:59

1 Answers1

3

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.

britzl
  • 10,132
  • 7
  • 41
  • 38