diff options
author | Chris Johns <chrisj@rtems.org> | 2023-06-21 10:33:46 +1000 |
---|---|---|
committer | Chris Johns <chrisj@rtems.org> | 2023-06-21 10:33:46 +1000 |
commit | 493c8bff70e36d547f54269bfcadd440b8323795 (patch) | |
tree | 21418c9b2d7f4f36ad3336b099f2b37da08ce245 | |
parent | tester/rt: use shlex.split to split command args (diff) | |
download | rtems-tools-493c8bff70e36d547f54269bfcadd440b8323795.tar.bz2 |
rtemstoolkil: Fix execute as strings after pipe addition
-rwxr-xr-x | rtemstoolkit/execute.py | 57 |
1 files changed, 35 insertions, 22 deletions
diff --git a/rtemstoolkit/execute.py b/rtemstoolkit/execute.py index 9ec1cd7..e47aa24 100755 --- a/rtemstoolkit/execute.py +++ b/rtemstoolkit/execute.py @@ -40,6 +40,7 @@ import functools import io import os import re +import shlex import sys import subprocess import threading @@ -389,7 +390,12 @@ class execute(object): r, e = os.path.splitext(command[0]) if e not in ['.exe', '.com', '.bat']: command[0] = command[0] + '.exe' - + # If a string split + if isinstance(command, str): + command = shlex.split(command, posix=False) + # See if there is a pipe operator in the command. If present + # split the commands by the pipe and run them with the pipe. + # if no pipe it is the normal stdin and stdout pipe_commands = [] current_command = [] for cmd in command: @@ -399,28 +405,35 @@ class execute(object): else: current_command.append(cmd) pipe_commands.append(current_command) - proc = None - for i, cmd in enumerate(pipe_commands): - if i == 0: - proc = subprocess.Popen( - cmd, shell=shell, - cwd=cwd, env=env, - stdin=stdin, stdout=subprocess.PIPE) - elif i == len(pipe_commands) - 1: - proc = subprocess.Popen( - cmd, shell=shell, - cwd=cwd, env=env, - stdin=proc.stdout, - stdout=stdout, stderr=stderr, - close_fds=False) - else: - proc = subprocess.Popen( - cmd, shell=shell, - cwd=cwd, env=env, - stdin=proc.stdout, - stdout=subprocess.PIPE) - + if len(pipe_commands) == 1: + cmd = pipe_commands[0] + proc = subprocess.Popen( + cmd, shell = shell, + cwd = cwd, env = env, + stdin = stdin, stdout = stdout, + stderr = stderr, + close_fds = False) + else: + for i, cmd in enumerate(pipe_commands): + if i == 0: + proc = subprocess.Popen( + cmd, shell=shell, + cwd=cwd, env=env, + stdin=stdin, stdout=subprocess.PIPE) + elif i == len(pipe_commands) - 1: + proc = subprocess.Popen( + cmd, shell=shell, + cwd=cwd, env=env, + stdin=proc.stdout, + stdout=stdout, stderr=stderr, + close_fds=False) + else: + proc = subprocess.Popen( + cmd, shell=shell, + cwd=cwd, env=env, + stdin=proc.stdout, + stdout=subprocess.PIPE) if not capture: return (0, proc) if self.output is None: |