Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions plumbum/commands/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ def machine(self):
return self.cmd.machine

def popen(self, args=(), **kwargs):
if "stdin" in kwargs and kwargs["stdin"] != PIPE:
if kwargs.get("stdin") not in (PIPE, None):
raise RedirectionError("stdin is already redirected")
data = self.data
if isinstance(data, str) and self._get_encoding() is not None:
Expand All @@ -558,8 +558,9 @@ def popen(self, args=(), **kwargs):
f.write(chunk)
data = data[self.CHUNK_SIZE :]
f.seek(0)
kwargs["stdin"] = f
# try:
return self.cmd.popen(args, stdin=f, **kwargs)
return self.cmd.popen(args, **kwargs)
# finally:
# f.close()

Expand Down
19 changes: 19 additions & 0 deletions tests/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,25 @@ def test_tee_race(self, capfd):
assert result[1] == EXPECT
assert EXPECT == capfd.readouterr()[0]

@skip_on_windows
@pytest.mark.parametrize(
"modifier, expected",
[
(FG, None),
(TF(FG=True), True),
(RETCODE(FG=True), 0),
(TEE, (0, "meow", "")),
],
)
def test_redirection_stdin_modifiers_fg(self, modifier, expected, capfd):
"StdinDataRedirection compatible with modifiers which write to stdout"
from plumbum.cmd import cat

cmd = cat << "meow"

assert cmd & modifier == expected
assert capfd.readouterr() == ("meow", "")

@skip_on_windows
def test_logger_pipe(self):
from plumbum.cmd import bash
Expand Down