diff options
| -rw-r--r-- | src/luarocks/core/util.lua | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/luarocks/core/util.lua b/src/luarocks/core/util.lua index 5f5c0fe1..8789851c 100644 --- a/src/luarocks/core/util.lua +++ b/src/luarocks/core/util.lua | |||
| @@ -12,10 +12,17 @@ local require = nil | |||
| 12 | -- May be used to read more, passing, for instance, "*a". | 12 | -- May be used to read more, passing, for instance, "*a". |
| 13 | -- @return string: the output of the program. | 13 | -- @return string: the output of the program. |
| 14 | function util.popen_read(cmd, spec) | 14 | function util.popen_read(cmd, spec) |
| 15 | local fd = io.popen(cmd) | 15 | local tmpfile = os.tmpname() |
| 16 | os.execute(cmd .. " > " .. tmpfile) | ||
| 17 | local fd = io.open(tmpfile, "rb") | ||
| 18 | if not fd then | ||
| 19 | os.remove(tmpfile) | ||
| 20 | return "" | ||
| 21 | end | ||
| 16 | local out = fd:read(spec or "*l") | 22 | local out = fd:read(spec or "*l") |
| 17 | fd:close() | 23 | fd:close() |
| 18 | return out | 24 | os.remove(tmpfile) |
| 25 | return out or "" | ||
| 19 | end | 26 | end |
| 20 | 27 | ||
| 21 | --- Create a new shallow copy of a table: a new table with | 28 | --- Create a new shallow copy of a table: a new table with |
