Created
August 26, 2014 22:17
-
-
Save eevee/78e52d55f171c78def0e to your computer and use it in GitHub Desktop.
plumbum patch to fix TEE with a stderr redirect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/plumbum/commands/modifiers.py b/plumbum/commands/modifiers.py | |
index 30f8dbf..1a5f8e6 100644 | |
--- a/plumbum/commands/modifiers.py | |
+++ b/plumbum/commands/modifiers.py | |
@@ -151,12 +151,26 @@ class TEE(ExecutionModifier): | |
with cmd.bgrun(retcode=self.retcode, stdin=None, stdout=PIPE, stderr=PIPE) as p: | |
outbuf = [] | |
errbuf = [] | |
+ buffers = {} | |
+ tee_to = {} | |
+ | |
out = p.stdout | |
err = p.stderr | |
- buffers = {out: outbuf, err: errbuf} | |
- tee_to = {out: sys.stdout, err: sys.stderr} | |
+ read_from = [] | |
+ if out: | |
+ buffers[out] = outbuf | |
+ tee_to[out] = sys.stdout | |
+ read_from.append(out) | |
+ if err: | |
+ buffers[err] = errbuf | |
+ tee_to[err] = sys.stderr | |
+ read_from.append(err) | |
+ | |
+ if not read_from: | |
+ raise IOError("Can't TEE a process with no stdout or stderr") | |
+ | |
while p.poll() is None: | |
- ready, _, _ = select((out, err), (), ()) | |
+ ready, _, _ = select(read_from, (), ()) | |
for fd in ready: | |
buf = buffers[fd] | |
data = os.read(fd.fileno(), 4096) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment