是否可以保存从os.execute("dir")
获取的目录信息转换成字符串形式?
所以在目录<DELL>
中我有文件info.txt
和readme.txt
。我想使用os.execute("dir")
并拥有文件 info.txt
和readme.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 (ifmode
is"r"
, the default) or to write data to this program (ifmode
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/