On Thu, Aug 26, 2021 at 5:53 AM Evan Greenup via Python-ideas < python-ideas@python.org> wrote:
> Currently, when what to execute external command, either os.system() or > subprocess functions should be invoked. > > However, it is not so convenient, it would be nice to use "``" symbol to > brace the shell command inside. > > like: > > stdout_result_str = `cat file.txt | sort | grep hello` > > Its is enhanced feature which combine both subprocess and os.system > > Because, subprocess can return output of file, but does not support pipe > in command. > subprocess.run('cat file.txt | sort |grep hello', shell=True capture_output=True, check=True, text=True, encoding="utf8").stdout you can use any piping or redirection you like. However, I do like the idea of run() having the ability to easily chain commands without the need to pull in the shell. Is this too magical? result = run('cat file.txt') | run('sort) | run('grep hello', capture_output=True, text=True).stdout I'm sure there are other approaches. We don't often have to worry about file handles in python, and it would be nice to remove this worry from subprocess pipes even more than it already is.
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/TXUDW3XOKASHSYD4JJYOFXCBFRXPGS5H/ Code of Conduct: http://python.org/psf/codeofconduct/