From cfd381134f36e7eff61f9f323830a73898b25d7f Mon Sep 17 00:00:00 2001 From: Bob Lantz Date: Wed, 9 May 2012 22:59:30 -0700 Subject: [PATCH] Fix errRun to not exit until all of stdout and stderr have been read. --- mininet/util.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/mininet/util.py b/mininet/util.py index e6ede1f..271cad4 100644 --- a/mininet/util.py +++ b/mininet/util.py @@ -74,31 +74,33 @@ def errRun( *cmd, **kwargs ): # cmd goes to stderr, output goes to stdout info( cmd, '\n' ) popen = Popen( cmd, stdout=PIPE, stderr=stderr, shell=shell ) - # We use poll() because select() doesn't work with large fd numbers + # We use poll() because select() doesn't work with large fd numbers, + # and thus communicate() doesn't work either out, err = '', '' poller = poll() poller.register( popen.stdout, POLLIN ) fdtofile = { popen.stdout.fileno(): popen.stdout } + outDone, errDone = False, True if popen.stderr: fdtofile[ popen.stderr.fileno() ] = popen.stderr poller.register( popen.stderr, POLLIN ) - while True: + errDone = False + while not outDone or not errDone: readable = poller.poll() - # Tell pylint to ignore unused variable event - # pylint: disable-msg=W0612 for fd, event in readable: - # pylint: enable-msg=W0612 f = fdtofile[ fd ] data = f.read( 1024 ) if echo: output( data ) if f == popen.stdout: out += data + if data == '': + outDone = True elif f == popen.stderr: err += data - returncode = popen.poll() - if returncode is not None: - break + if data == '': + errDone = True + returncode = popen.wait() return out, err, returncode def errFail( *cmd, **kwargs ):