EDIT: Came back here: it works like a charm with subprocess from python3 and if you are on linux, there is a backport to python2 called subprocess32subprocess32 which does the work quite well
SOLVED: I used pexpect and it works
def cmdlineCall(name, args): child = pexpect.spawn(name, args) # Wait for the end of the output child.expect(pexpect.EOF) out = child.before # we get all the data before the EOF (stderr and stdout) child.close() # that will set the return code for us # signalstatus and existstatus read as the same (for my purpose only) if child.exitstatus is None: returncode = child.signalstatus else: returncode=child.exitstatus return (out,returncode)
Older solution: I used pexpect and it works
def cmd_line_call(name, args): child = pexpect.spawn(name, args) # Wait for the end of the output child.expect(pexpect.EOF) out = child.before # we get all the data before the EOF (stderr and stdout) child.close() # that will set the return code for us # signalstatus and existstatus read as the same (for my purpose only) if child.exitstatus is None: returncode = child.signalstatus else: returncode = child.exitstatus return (out, returncode) PS: a little slower (because it spawnspawns a pseudo tty)