如何在Lua中获取os.execute的输出结果

我想将 shell 命令的结果赋给 lua 变量。

在 lua 5.1 中是否有比 Get back the output of os.execute in Lua 中提供的更好的方法?

原文链接 https://stackoverflow.com/questions/6032951

点赞
stackoverflow用户513763
stackoverflow用户513763

你可以使用io.popen来实现这个功能(在Lua 5.1中已经包含)。这会给你一个文件句柄,你可以用来写入或从程序读取内容。更多信息在Lua手册中。

2011-05-17 20:37:44