> Is this too magical?
> result = run('cat file.txt') | run('sort) | run('grep hello',
capture_output=True, text=True).stdout

Interesting idea, especially overloading the union/pipe operator (|). I
like it a lot. It reminds me of pathlib.Path (which is a wonderful tool),
with its slash operator overload.
Python is supposed to be easy to read and understand, and anything that
makes complicated system stuff less messy is welcome, I think.
Another idea (which I am less in favor of) is a more functional approach,
like:

run('grep hello', run('sort', run('cat file.txt')))

In this version, it looks more like Python functions than pipes, where the
last (optional) argument is what's piped in. This makes more sense in a
functional context and may eliminate the need for capture_output=True,
text=True, .stdout, and similar idioms.
Like I said, I'm not as much in favor of this, though, because it doesn't
resemble an actual call as much. However, it's still an idea.
It might be helpful to point out that Jeremiah's version would have to be
implemented as a class because of the union operator overload.



On Thu, Aug 26, 2021, 8:44 PM Jeremiah Paige <ucod...@gmail.com> wrote:

>
>
> 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/
>
_______________________________________________
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/O36BRLR4Q2NULI3HQQY27ALZCJ362U3Q/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to