<div dir="ltr"><span style="color:rgb(80,0,80)">> On 21/6/2023 11:55 am, Muhammad Sulthan Mazaya wrote:<br>> > Turns out subprocess.Popen operates on posix mode.<br>><br></span>> Is this true for non-POSIX systems?<br>><br>> Where is this documented?<br><br>It's not, turns out it is also dependent on the system too. It is documented here <a href="https://docs.python.org/3/library/subprocess.html#subprocess.Popen" target="_blank">https://docs.python.org/3/library/subprocess.html#subprocess.Popen</a>. Should I add a check like this instead?<br><br>---<br> rtemstoolkit/execute.py | 21 ++++++++++++++-------<br> tester/rt/config.py | 2 +-<br> 2 files changed, 15 insertions(+), 8 deletions(-)<br><br>diff --git a/rtemstoolkit/execute.py b/rtemstoolkit/execute.py<br>index e47aa24..5f0d94b 100755<br>--- a/rtemstoolkit/execute.py<br>+++ b/rtemstoolkit/execute.py<br>@@ -392,7 +392,7 @@ class execute(object):<br> command[0] = command[0] + '.exe'<br> # If a string split<br> if isinstance(command, str):<br>- command = shlex.split(command, posix=False)<br>+ command = shlex.split(command, posix=(<a href="http://os.name">os.name</a> == 'posix'))<br> # See if there is a pipe operator in the command. If present<br> # split the commands by the pipe and run them with the pipe.<br> # if no pipe it is the normal stdin and stdout<br>@@ -623,10 +623,11 @@ 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>+ for c in commands['open']:<br>+ ec, proc = e.open(c)<br>+ if ec == 0:<br>+ e.capture(proc)<br>+ del proc<br> <br> def capture_output(text):<br> print(text, end = '')<br>@@ -645,7 +646,10 @@ 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['windows']['open'] = [<br>+ ["echo", "hello rtems", "|", "findstr", "rtems"],<br>+ " ".join(["echo", "hello rtems", "|", "findstr", "rtems"])<br>+ ]<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>@@ -653,7 +657,10 @@ 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>+ commands['unix']['open'] = [<br>+ ["echo", "hello world", "|", "cut", "-d ", "-f2"],<br>+ " ".join(["echo", "hello world", "|", "cut", "-d\" \"", "-f2"])<br>+ ]<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>diff --git a/tester/rt/config.py b/tester/rt/config.py<br>index c0c31de..ceb044e 100644<br>--- a/tester/rt/config.py<br>+++ b/tester/rt/config.py<br>@@ -327,7 +327,7 @@ class file(config.file):<br> if len(_data):<br> ds = [_data[0]]<br> if len(_data) > 1:<br>- ds += shlex.split(_data[1], posix=False)<br>+ ds += shlex.split(_data[1], posix=(<a href="http://os.name">os.name</a> == 'posix'))<br> ds = self.expand(ds)<br> <br> if _directive == '%console':<br>-- <br>2.34.1<br><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jun 21, 2023 at 1:27 PM Chris Johns <<a href="mailto:chrisj@rtems.org" target="_blank">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">On 21/6/2023 11:55 am, Muhammad Sulthan Mazaya wrote:<br>
> Turns out subprocess.Popen operates on posix mode. <br>
<br>
Is this true for non-POSIX systems?<br>
<br>
Where is this documented?<br>
<br>
Chris<br>
<br>
Also, there is an<br>
> issue with previous implementation of pipe command that is fixed by<br>
> Chris. Now, it can also accepts command in form of a string. The unit<br>
> test for that is added via this patch.<br>
> <br>
> ---<br>
> rtemstoolkit/execute.py | 21 ++++++++++++++-------<br>
> tester/rt/config.py | 2 +-<br>
> 2 files changed, 15 insertions(+), 8 deletions(-)<br>
> <br>
> diff --git a/rtemstoolkit/execute.py b/rtemstoolkit/execute.py<br>
> index e47aa24..3b7dcb0 100755<br>
> --- a/rtemstoolkit/execute.py<br>
> +++ b/rtemstoolkit/execute.py<br>
> @@ -392,7 +392,7 @@ class execute(object):<br>
> command[0] = command[0] + '.exe'<br>
> # If a string split<br>
> if isinstance(command, str):<br>
> - command = shlex.split(command, posix=False)<br>
> + command = shlex.split(command)<br>
> # See if there is a pipe operator in the command. If present<br>
> # split the commands by the pipe and run them with the pipe.<br>
> # if no pipe it is the normal stdin and stdout<br>
> @@ -623,10 +623,11 @@ 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>
> + for c in commands['open']:<br>
> + ec, proc = e.open(c)<br>
> + if ec == 0:<br>
> + e.capture(proc)<br>
> + del proc<br>
> <br>
> def capture_output(text):<br>
> print(text, end = '')<br>
> @@ -645,7 +646,10 @@ 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['windows']['open'] = [<br>
> + ["echo", "hello rtems", "|", "findstr", "rtems"],<br>
> + " ".join(["echo", "hello rtems", "|", "findstr", "rtems"])<br>
> + ]<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>
> @@ -653,7 +657,10 @@ 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>
> + commands['unix']['open'] = [<br>
> + ["echo", "hello world", "|", "cut", "-d ", "-f2"],<br>
> + " ".join(["echo", "hello world", "|", "cut", "-d\" \"", "-f2"])<br>
> + ]<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>
> diff --git a/tester/rt/config.py b/tester/rt/config.py<br>
> index c0c31de..3b12c6c 100644<br>
> --- a/tester/rt/config.py<br>
> +++ b/tester/rt/config.py<br>
> @@ -327,7 +327,7 @@ class file(config.file):<br>
> if len(_data):<br>
> ds = [_data[0]]<br>
> if len(_data) > 1:<br>
> - ds += shlex.split(_data[1], posix=False)<br>
> + ds += shlex.split(_data[1])<br>
> ds = self.expand(ds)<br>
> <br>
> if _directive == '%console':<br>
_______________________________________________<br>
devel mailing list<br>
<a href="mailto:devel@rtems.org" target="_blank">devel@rtems.org</a><br>
<a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/devel</a><br>
</blockquote></div>