<div dir="ltr">Now that this is pushed, the hash for rtems-tools in the RSB needs to be bumped to pick these changes up.<div><br></div><div>--joel</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jun 20, 2023 at 6:04 PM Chris Johns <<a href="mailto:chrisj@rtems.org">chrisj@rtems.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Module:    rtems-tools<br>
Branch:    master<br>
Commit:    38162e17d998770cd4696bcd4f01c98b5d8c53a0<br>
Changeset: <a href="http://git.rtems.org/rtems-tools/commit/?id=38162e17d998770cd4696bcd4f01c98b5d8c53a0" rel="noreferrer" target="_blank">http://git.rtems.org/rtems-tools/commit/?id=38162e17d998770cd4696bcd4f01c98b5d8c53a0</a><br>
<br>
Author:    Muhammad Sulthan Mazaya <<a href="mailto:msulthanmazaya@gmail.com" target="_blank">msulthanmazaya@gmail.com</a>><br>
Date:      Tue Jun 20 12:32:06 2023 +1000<br>
<br>
rtemstoolkit: add support for executing pipe command<br>
<br>
added unit tests and shorten long lines.<br>
<br>
---<br>
<br>
 rtemstoolkit/execute.py | 43 ++++++++++++++++++++++++++++++++++++++-----<br>
 1 file changed, 38 insertions(+), 5 deletions(-)<br>
<br>
diff --git a/rtemstoolkit/execute.py b/rtemstoolkit/execute.py<br>
index ed81589..9ec1cd7 100755<br>
--- a/rtemstoolkit/execute.py<br>
+++ b/rtemstoolkit/execute.py<br>
@@ -389,11 +389,38 @@ class execute(object):<br>
                     r, e = os.path.splitext(command[0])<br>
                     if e not in ['.exe', '.com', '.bat']:<br>
                         command[0] = command[0] + '.exe'<br>
-            proc = subprocess.Popen(command, shell = shell,<br>
-                                    cwd = cwd, env = env,<br>
-                                    stdin = stdin, stdout = stdout,<br>
-                                    stderr = stderr,<br>
-                                    close_fds = False)<br>
+                        <br>
+            pipe_commands = []<br>
+            current_command = []<br>
+            for cmd in command:<br>
+                if cmd == '|':<br>
+                    pipe_commands.append(current_command)<br>
+                    current_command = []<br>
+                else:<br>
+                    current_command.append(cmd)<br>
+            pipe_commands.append(current_command)<br>
+<br>
+            proc = None<br>
+            for i, cmd in enumerate(pipe_commands):<br>
+                if i == 0:<br>
+                    proc = subprocess.Popen(<br>
+                        cmd, shell=shell,<br>
+                        cwd=cwd, env=env,<br>
+                        stdin=stdin, stdout=subprocess.PIPE)<br>
+                elif i == len(pipe_commands) - 1:<br>
+                    proc = subprocess.Popen(<br>
+                        cmd, shell=shell,<br>
+                        cwd=cwd, env=env,<br>
+                        stdin=proc.stdout,<br>
+                        stdout=stdout, stderr=stderr,<br>
+                        close_fds=False)<br>
+                else:<br>
+                    proc = subprocess.Popen(<br>
+                        cmd, shell=shell,<br>
+                        cwd=cwd, env=env,<br>
+                        stdin=proc.stdout,<br>
+                        stdout=subprocess.PIPE)<br>
+<br>
             if not capture:<br>
                 return (0, proc)<br>
             if self.output is None:<br>
@@ -583,6 +610,10 @@ if __name__ == "__main__":<br>
             proc.stdin.close()<br>
             e.capture(proc)<br>
             del proc<br>
+        ec, proc = e.open(commands['open'])<br>
+        if ec == 0:<br>
+            e.capture(proc)<br>
+            del proc<br>
<br>
     def capture_output(text):<br>
         print(text, end = '')<br>
@@ -601,6 +632,7 @@ if __name__ == "__main__":<br>
     commands['windows']['csubsts'] = [('netstat %0', ['-a']),<br>
                                       ('netstat %0 %1', ['-a', '-n'])]<br>
     commands['windows']['pipe'] = ('ftp', None, 'help\nquit')<br>
+    commands['windows']['open'] = ["echo",  "hello rtems", "|", "findstr", "rtems"]<br>
     commands['unix']['shell'] = ['pwd', 'ls -las', './xyz', sh_shell_test]<br>
     commands['unix']['spawn'] = ['ls', 'execute.pyc', ['ls', '-i']]<br>
     commands['unix']['cmd'] = [('date'), ('date', '-R'), ('date', ['-u', '+%d %D']),<br>
@@ -608,6 +640,7 @@ if __name__ == "__main__":<br>
     commands['unix']['csubsts'] = [('date %0 "+%d %D %S"', ['-u']),<br>
                                    ('date %0 %1', ['-u', '+%d %D %S'])]<br>
     commands['unix']['pipe'] = ('grep', 'hello', 'hello world')<br>
+    commands['unix']['open'] = ["echo", "hello world", "|", "cut", "-d ", "-f2"]<br>
<br>
     print(arg_list('cmd a1 a2 "a3 is a string" a4'))<br>
     print(arg_list('cmd b1 b2 "b3 is a string a4'))<br>
<br>
_______________________________________________<br>
vc mailing list<br>
<a href="mailto:vc@rtems.org" target="_blank">vc@rtems.org</a><br>
<a href="http://lists.rtems.org/mailman/listinfo/vc" rel="noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/vc</a><br>
</blockquote></div>