diff options
author | Muhammad Sulthan Mazaya <msulthanmazaya@gmail.com> | 2023-06-21 11:55:10 +1000 |
---|---|---|
committer | Chris Johns <chrisj@rtems.org> | 2023-06-21 14:30:48 +1000 |
commit | bd2d3d5523ea203f9e0122a1def61cd2d35d74ab (patch) | |
tree | 463308b574a6cef4eb815a9a026d111a2aab6fbc /rtemstoolkit | |
parent | rtemstoolkil: Fix execute as strings after pipe addition (diff) | |
download | rtems-tools-bd2d3d5523ea203f9e0122a1def61cd2d35d74ab.tar.bz2 |
rtemstoolkit: Fix shlex.split to use posix mode and add unit test for pipe operation
Turns out subprocess.Popen operates on posix mode. Also, there is an
issue with previous implementation of pipe command that is fixed by
Chris. Now, it can also accepts command in form of a string. The unit
test for that is added via this patch.
Diffstat (limited to 'rtemstoolkit')
-rwxr-xr-x | rtemstoolkit/execute.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/rtemstoolkit/execute.py b/rtemstoolkit/execute.py index e47aa24..3b7dcb0 100755 --- a/rtemstoolkit/execute.py +++ b/rtemstoolkit/execute.py @@ -392,7 +392,7 @@ class execute(object): command[0] = command[0] + '.exe' # If a string split if isinstance(command, str): - command = shlex.split(command, posix=False) + command = shlex.split(command) # 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 @@ -623,10 +623,11 @@ if __name__ == "__main__": proc.stdin.close() e.capture(proc) del proc - ec, proc = e.open(commands['open']) - if ec == 0: - e.capture(proc) - del proc + for c in commands['open']: + ec, proc = e.open(c) + if ec == 0: + e.capture(proc) + del proc def capture_output(text): print(text, end = '') @@ -645,7 +646,10 @@ if __name__ == "__main__": commands['windows']['csubsts'] = [('netstat %0', ['-a']), ('netstat %0 %1', ['-a', '-n'])] commands['windows']['pipe'] = ('ftp', None, 'help\nquit') - commands['windows']['open'] = ["echo", "hello rtems", "|", "findstr", "rtems"] + commands['windows']['open'] = [ + ["echo", "hello rtems", "|", "findstr", "rtems"], + " ".join(["echo", "hello rtems", "|", "findstr", "rtems"]) + ] commands['unix']['shell'] = ['pwd', 'ls -las', './xyz', sh_shell_test] commands['unix']['spawn'] = ['ls', 'execute.pyc', ['ls', '-i']] commands['unix']['cmd'] = [('date'), ('date', '-R'), ('date', ['-u', '+%d %D']), @@ -653,7 +657,10 @@ if __name__ == "__main__": commands['unix']['csubsts'] = [('date %0 "+%d %D %S"', ['-u']), ('date %0 %1', ['-u', '+%d %D %S'])] commands['unix']['pipe'] = ('grep', 'hello', 'hello world') - commands['unix']['open'] = ["echo", "hello world", "|", "cut", "-d ", "-f2"] + commands['unix']['open'] = [ + ["echo", "hello world", "|", "cut", "-d ", "-f2"], + " ".join(["echo", "hello world", "|", "cut", "-d\" \"", "-f2"]) + ] print(arg_list('cmd a1 a2 "a3 is a string" a4')) print(arg_list('cmd b1 b2 "b3 is a string a4')) |