When writing a lua script, I came across one thing: io.popen, judging by the documentation, cannot transfer the descriptors stdin and stdout of the process being started at the same time.
Example problem code:
cmdexecute = function(cmd, input) local f = io.popen(cmd, "w"); if tostring(input) ~= nil then f:write(tostring(input)); end; local l = f:read("*a"); f:close(); return (l); end; if cmdexecute('xargs ps', 'aux') ~= nil then print 'ps aux что-то выдал'; else print 'ps aux промолчал'; end;
Result of performance:
Длинный-длинный вывод ps aux... ps aux промолчал
But it should be in theory:
ps aux что-то выдал
Question: how to get descriptors for both stdin and stdout from popen? Or perhaps there is some other solution to the problem, without io.popen
?
Upd: due to the relevance of the issue I explain: solutions with ffi
valid .