使用LUA执行PowerShell命令



我有一个与我合作的程序,该程序具有载板LUA编译器,可以允许自定义书面操作。

由于该工具本身非常有限,尤其是在网络上进行复杂的反应时,我想在LUA上使用PowerShell。

os.execute()io.popen()之类的方法使用Windows而非PowerShell的标准命令行。

有没有办法将powershell与lua?


我试图用PowerShell编辑器编写命令行脚本并使用OS.ectute运行此脚本,但是它将其打开为文本文件,最好直接在LUA中编写命令,但是如果没有其他方法,直接执行PowerShell脚本也可以。(在Windows本身中,您可以使用正确的鼠标执行脚本"单击/执行PowerShell")

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

您对问题的描述听起来就像您使用了诸如 os.execute("powershellscript.ps1")之类的命令,并且呼叫用字符串作为建议的命令行调用 cmd.exe。通常,Windows将打开.PS1文件进行编辑;这是故意的安全决定。而是尝试更改os.execute()命令以明确调用PS:os.execute("powershell.exe -file powershellscript.ps1")。如果您需要将参数传递给脚本,请将其包装在{}中。请参阅https://msdn.microsoft.com/en-us/powershell/scripting/core-powershell/console/console/powershell.exe-command-line-line-help,以获取有关命令行调用powershell的更多信息。/div>

最新更新