tee-like behavior in Python

Chris Rebert clp2 at rebertia.com
Wed May 9 17:51:35 EDT 2012


On Wed, May 9, 2012 at 8:35 AM, Florian Lindner <mailinglists at xgm.de> wrote:
> Hello,
>
> how can I achieve a behavior like tee in Python?
>
> * execute an application
> * leave the output to stdout and stderr untouched
> * but capture both and save it to a file (resp. file-like object)
>
> I have this code
>
> proc = subprocess.Popen(shlex.split(cmd), stdout = subprocess.PIPE,

shlex.split() should just be used once, at "development time", to
determine the form of the argument list. It shouldn't generally be
used at runtime. Otherwise, you need to do the proper escaping/quoting
yourself, which defeats the entire purpose of bypassing the shell.

Cheers,
Chris



More information about the Python-list mailing list