我怎么能start/display一个文件在lua,就像批处理命令"start"?

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

我查看了 lua 中的 opening/starting 文件,但是每篇文章都给我提供了像 dofile() 这样的函数,returns/runs 文件 status/contents,而不是实际上 opening/starting 文件。在我的场景中,我有一个 .hta 文件,我试图通过 lua 开始,我在技术上想知道 lua 是否具有类似于批处理命令 "start" 的功能,即启动一个文件,如果没有,是否有任何方法可以从 lua 文件向控制台发送命令?如果有人能帮助我,我将不胜感激。

您要找的是os.execute()。它允许您 运行 操作系统中的命令 shell:

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

如果您还想捕获已执行命令的输出并在您的 Lua 代码中使用它,您可以使用 io.popen():

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

请注意,io.popen() 并非在所有系统上都可用。