lua - 如何将 os.execute ("dir") 中的目录信息保存到字符串中?

标签 lua

是否可以保存从os.execute("dir")获取的目录信息转换成字符串形式?

所以在目录<DELL>中我有文件info.txtreadme.txt 。我想使用os.execute("dir")并拥有文件 info.txtreadme.txt保存到字符串 DIR 。所以我猜整个字符串会读成类似 DELL; info.txt, readme.txt .

最佳答案

不,但使用 io.popen应该可以。

io.popen (prog [, mode])

This function is system dependent and is not available on all platforms.

Starts program prog in a separated process and returns a file handle that you can use to read data from this program (if mode is "r", the default) or to write data to this program (if mode is "w").

local p = io.popen( "dir", "r" )
local output = p:read "*a"
p:close( )
-- and use output

关于lua - 如何将 os.execute ("dir") 中的目录信息保存到字符串中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29868813/

相关文章:

oop - 我如何在 lua love2d (OOP) 中使用类

memory - 如何在 Lua 中获取 "sizeof"表?

c - 如何在C中读取lua表

javascript - 哪种脚本语言更适合嵌入多线程 C/C++ 应用程序

loops - 在 Lua 中,变量意外地为 nil

loops - Lua 尾调用 vs 循环

string - 当我们在 Lua 中没有 `|` 运算符时如何验证这个字符串?

gcc - Asm 代码说明

lua - redis lua 调试器——为什么我不能打印 ARGV

nginx - 在 if 之前运行 access_by_lua