Skip to content

Commit 2d3b1ad

Browse files
KotlinIslandpre-commit-ci[bot]ssbarnea
authored
Use exec mode when passed a list of strings (#101)
* use exec mode when passed a list of strings * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: KotlinIsland <kotlinisland@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Sorin Sbarnea <ssbarnea@redhat.com>
1 parent c6337b4 commit 2d3b1ad

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

src/subprocess_tee/__init__.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ async def _read_stream(stream: StreamReader, callback: Callable[..., Any]) -> No
3535
break
3636

3737

38-
async def _stream_subprocess(args: str, **kwargs: Any) -> CompletedProcess:
38+
async def _stream_subprocess(
39+
args: Union[str, List[str]], **kwargs: Any
40+
) -> CompletedProcess:
3941
platform_settings: Dict[str, Any] = {}
4042
if platform.system() == "Windows":
4143
platform_settings["env"] = os.environ
@@ -65,14 +67,24 @@ async def _stream_subprocess(args: str, **kwargs: Any) -> CompletedProcess:
6567

6668
# Some users are reporting that default (undocumented) limit 64k is too
6769
# low
68-
process = await asyncio.create_subprocess_shell(
69-
args,
70-
limit=STREAM_LIMIT,
71-
stdin=kwargs.get("stdin", False),
72-
stdout=asyncio.subprocess.PIPE,
73-
stderr=asyncio.subprocess.PIPE,
74-
**platform_settings,
75-
)
70+
if isinstance(args, str):
71+
process = await asyncio.create_subprocess_shell(
72+
args,
73+
limit=STREAM_LIMIT,
74+
stdin=kwargs.get("stdin", False),
75+
stdout=asyncio.subprocess.PIPE,
76+
stderr=asyncio.subprocess.PIPE,
77+
**platform_settings,
78+
)
79+
else:
80+
process = await asyncio.create_subprocess_exec(
81+
*args,
82+
limit=STREAM_LIMIT,
83+
stdin=kwargs.get("stdin", False),
84+
stdout=asyncio.subprocess.PIPE,
85+
stderr=asyncio.subprocess.PIPE,
86+
**platform_settings,
87+
)
7688
out: List[str] = []
7789
err: List[str] = []
7890

@@ -140,7 +152,7 @@ def run(args: Union[str, List[str]], **kwargs: Any) -> CompletedProcess:
140152
if kwargs.get("echo", False):
141153
print(f"COMMAND: {cmd}")
142154

143-
result = asyncio.run(_stream_subprocess(cmd, **kwargs))
155+
result = asyncio.run(_stream_subprocess(args, **kwargs))
144156
# we restore original args to mimic subproces.run()
145157
result.args = args
146158

0 commit comments

Comments
 (0)