使用 Lua 执行 powershell 命令 [英] execute powershell commands with Lua

查看:28
本文介绍了使用 Lua 执行 powershell 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

晚上好,

我有一个与我一起工作的程序,它有一个板载 lua 编译器,可以进行自定义的书面操作.

I have a program that I work with, that has an onboard lua compiler to allow for custom written actions.

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

Since the tool itself is very limited, especially if it goes for complex reactions over networks, I want to use Powershell over lua.

遗憾的是没有太多可找到的(至少我没有),还有诸如 os.execute()io.popen() 之类的东西使用 Windows 中的标准命令行.

Sadly there isn't much to find about that (at least I didn't), and things like os.execute() or io.popen() use the standard command line from windows.

有人知道一个库或其他使用 lua 的 Powershell 的方法吗.

Does someone know a library or another way to use Powershell with lua.

我已经尝试过的:我试图用Powershell编辑器编写一个命令行脚本并用os.execute运行这个脚本,但它以文本文件的形式打开它,最好直接在lua中编写命令但如果没有其他方法,执行一个直接使用 Powershell 脚本也可以.(在 Windows 本身中,您可以使用鼠标右键单击/使用 Powershell 执行"来执行脚本

What I already tried: I tried to write a command line script with the Powershell editor and run this script with os.execute, but it opens it as a textfile, it would be better to write the commands directly in lua but if there is no other way, executing a Powershell script directly would also be fine. (In Windows itself you can execute the script with right mouse "click/Execute with 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()

这篇关于使用 Lua 执行 powershell 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆