So from what I can tell you're code won't work for a number of reasons. The most fundamental is the way you've strung your commands together won't capture the output. The cd command fails long before you've asked bash to pipe stderr to sdtout. io.popen won't work for your needs. The restriction seems to be in the underlying C library
popen(3):
popen(): on success, returns a pointer to an open stream that can
be used to read or write to the pipe; if the
fork(2) or
pipe(2)
calls fail, or if the function cannot allocate memory,
NULL is
returned.
Luaposix is the most robust solution, but I understand cross compiling C for luaposix may not be desirable. (If your router supports lua, it may have luaposix already on it? I forget which distros used Lua, was it openwrt?).
As an alternative, There is a suggestion to use a temp file in a lua-l thread:
Re: io.popen: reading both stdout AND stderr
Some questions:
- Do you have to string the commands together with '&&'? Could you use a script? (Much easier to redirect one call to a script)
- Not sure if you have a filesystem on a router in which to store the temp file?
Perhaps you could answer the above and provide more context about what you're doing there could be some ways forward? I don't think stringing commands together as you have is going to work though.
As another suggestion, the lua-l mailing list is where the creators and experts can answer your questions:
Lua: mailing list (click the little 'join' link). Your use case is quiet advanced, there may be more help available on a forum for the router?
Cheers.