Reputation: 183
I would like to take the result of f = io.popen(command)
to a file. Is there a way to do it from the file-descriptor f
, or do I have to copy the data to a new string and write that via a new file-descriptor?
Upvotes: 2
Views: 1600
Reputation: 14565
this is about as simple as it's going to get without knowing more about what you're trying to do...
local fout = io.open("/path/to/file", "w+")
f = io.popen(command)
fout:write(f:read("*a"))
Upvotes: 3
Reputation: 41403
No standard way to do that in plain Lua. But you always may redirect the output to file in the command
itself. (I.e. io.popen("echo foo | tee bar")
, or os.execute("echo foo >bar")
.)
Upvotes: 0