Reputation: 15
Is it possible to save the directory info obtained from os.execute("dir")
into a string form?
So in the directory <DELL>
I have the files info.txt
and readme.txt
. I want to use os.execute("dir")
and have the files info.txt
and readme.txt
saved into string DIR
. So I guess the entire string would read something like DELL; info.txt, readme.txt
.
Upvotes: 2
Views: 295
Reputation: 4264
No, but using io.popen
should work.
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
Upvotes: 5