# HG changeset patch # User Gilles Duboscq # Date 1383675052 -3600 # Node ID 697ef4cf18c0ef6dbae3d1b1ec3adb5362b5230f # Parent 76a6070f7164752caa0e12b3bc3df437a5ae10f6 mx.run should support streams for out/err even if there is no timeout diff -r 76a6070f7164 -r 697ef4cf18c0 mxtool/mx.py --- a/mxtool/mx.py Wed Nov 06 11:04:01 2013 +0100 +++ b/mxtool/mx.py Tue Nov 05 19:10:52 2013 +0100 @@ -1425,34 +1425,28 @@ else: preexec_fn = os.setsid - if not callable(out) and not callable(err) and timeout is None: - # The preexec_fn=os.setsid - p = subprocess.Popen(args, cwd=cwd, preexec_fn=preexec_fn, creationflags=creationflags, env=env) - _currentSubprocess = (p, args) + def redirect(stream, f): + for line in iter(stream.readline, ''): + f(line) + stream.close() + stdout = out if not callable(out) else subprocess.PIPE + stderr = err if not callable(err) else subprocess.PIPE + p = subprocess.Popen(args, cwd=cwd, stdout=stdout, stderr=stderr, preexec_fn=preexec_fn, creationflags=creationflags, env=env) + _currentSubprocess = (p, args) + if callable(out): + t = Thread(target=redirect, args=(p.stdout, out)) + t.daemon = True # thread dies with the program + t.start() + if callable(err): + t = Thread(target=redirect, args=(p.stderr, err)) + t.daemon = True # thread dies with the program + t.start() + if timeout is None or timeout == 0: retcode = waitOn(p) else: - def redirect(stream, f): - for line in iter(stream.readline, ''): - f(line) - stream.close() - stdout = out if not callable(out) else subprocess.PIPE - stderr = err if not callable(err) else subprocess.PIPE - p = subprocess.Popen(args, cwd=cwd, stdout=stdout, stderr=stderr, preexec_fn=preexec_fn, creationflags=creationflags, env=env) - _currentSubprocess = (p, args) - if callable(out): - t = Thread(target=redirect, args=(p.stdout, out)) - t.daemon = True # thread dies with the program - t.start() - if callable(err): - t = Thread(target=redirect, args=(p.stderr, err)) - t.daemon = True # thread dies with the program - t.start() - if timeout is None or timeout == 0: - retcode = waitOn(p) - else: - if get_os() == 'windows': - abort('Use of timeout not (yet) supported on Windows') - retcode = _waitWithTimeout(p, args, timeout) + if get_os() == 'windows': + abort('Use of timeout not (yet) supported on Windows') + retcode = _waitWithTimeout(p, args, timeout) except OSError as e: log('Error executing \'' + ' '.join(args) + '\': ' + str(e)) if _opts.verbose: