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

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

问题描述

晚上好

我有一个可以使用的程序,它带有一个内置的lua编译器,可以进行自定义的书面操作.

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

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

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天全站免登陆