Skip to content

Commit

Permalink
Fix missing non-zero return code from TEE'd pipe (#661)
Browse files Browse the repository at this point in the history
* Fix missing non-zero return code from TEE'd pipe

* fix
  • Loading branch information
vient authored Nov 1, 2023
1 parent 38a108b commit 8bac666
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions plumbum/commands/modifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ def __rand__(self, cmd):

buf.append(data)

p.wait() # To get return code in p
stdout = "".join([x.decode("utf-8") for x in outbuf])
stderr = "".join([x.decode("utf-8") for x in errbuf])
return p.returncode, stdout, stderr
Expand Down
8 changes: 7 additions & 1 deletion tests/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,19 +607,25 @@ def test_iter_lines_line_timeout(self):

@skip_on_windows
def test_modifiers(self):
from plumbum.cmd import grep, ls
from plumbum.cmd import cat, grep, ls

f = (ls["-a"] | grep["\\.py"]) & BG
f.wait()
assert "test_local.py" in f.stdout.splitlines()

command = ls["-a"] | grep["local"]
command_false = ls["-a"] | grep["not_a_file_here"]
command_false_2 = command_false | cat
command & FG
assert command & TF
assert not (command_false & TF)
assert not (command_false_2 & TF)
assert command & RETCODE == 0
assert command_false & RETCODE == 1
assert command_false_2 & RETCODE == 1
assert (command & TEE)[0] == 0
assert (command_false & TEE(retcode=None))[0] == 1
assert (command_false_2 & TEE(retcode=None))[0] == 1

@skip_on_windows
def test_tee_modifier(self, capfd):
Expand Down

0 comments on commit 8bac666

Please sign in to comment.