You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.
This will be much easier with python 3.4+ (even better, 3.5).
A solution only requiring smsll-ish dependencies is using trollius, a backport of asyncio present in epel.
The command would look something like:
importtrolliusfromtrolliusimportFrom, Return@trollius.coroutinedef_read_stream(stream, cbk):
""" Read from stream line by line until EOF and run the callback cb on the lines. """whileTrue:
line=yieldFrom(stream.readline())
ifline:
cbk(line)
else:
break@trollius.coroutinedef_stream_subprocess(cmd, stdout_cb, stderr_cb, env):
""" Capture cmd's stdout, stderr (line by line) executing the stdout_cb and stderr_cb callbacks as they arrive. """process=yieldFrom(trollius.create_subprocess_exec(
*cmd,
stdout=trollius.subprocess.PIPE, stderr=trollius.subprocess.PIPE,
env=env))
yieldFrom(trollius.wait([
_read_stream(process.stdout, stdout_cb),
_read_stream(process.stderr, stderr_cb)
]))
yieldFrom(process.communicate())
raiseReturn(process.returncode)
defexecute(cmd, stdout_cb, stderr_cb, env):
""" Run cmd and process stdout and stderr concurrently line by line. """loop=trollius.get_event_loop()
retc=loop.run_until_complete(
_stream_subprocess(
cmd,
stdout_cb,
stderr_cb,
env
))
returnretcdefrun_with_live_stdout(cmd, env=None):
""" Run cmd in a subprocess, piping out the stdout. """ifenvisNone:
env=os.environ.copy()
stderr= []
print("+ %s"%" ".join(cmd))
ret=execute(cmd, lambdao: print(o, end=""), stderr.append, env)
ifret!=0:
print(" ".join(stderr))
raiseException("Error while running\n\t%s"%" ".join(cmd))
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Currently
utils.run(cmd)
swallows stdout and stderr and by default only prints them ifcmd
fails.The text was updated successfully, but these errors were encountered: