使用Lua执行powershell命令

Eta*_*ila 2 windows powershell lua execute

我有一个正在使用的程序,它有一个板载 lua 编译器,允许自定义写入操作。

由于该工具本身非常有限,特别是如果它需要通过网络进行复杂的反应,我想使用 Powershell 而不是 lua。

方法类似于os.execute()io.popen()使用 Windows 中的标准命令行,而不是 Powershell。

有没有办法将Powershell与lua一起使用?


我尝试使用Powershell编辑器编写一个命令行脚本,并使用os.execute运行该脚本,但它将它作为文本文件打开,最好直接在lua中编写命令,但如果没有其他方法,请执行直接使用 Powershell 脚本也可以。(在 Windows 本身中,您可以使用鼠标右键“单击/使用 Powershell 执行”来执行脚本)

Ego*_*off 6

-- You can generate PowerShell script at run-time
local script = [[
Write-Host "Hello, World!"
]]
-- Now create powershell process and feed your script to its stdin
local pipe = io.popen("powershell -command -", "w")
pipe:write(script)
pipe:close()
Run Code Online (Sandbox Code Playgroud)