how to use subprocess.Popen execute "find" in windows

clyfish at gmail.com clyfish at gmail.com
Fri May 9 02:39:48 EDT 2008


On 5月8日, 下午5时39分, "Gabriel Genellina" <gagsl-... at yahoo.com.ar> wrote:
> En Wed, 07 May 2008 23:29:58 -0300, <clyf... at gmail.com> escribió:
>
>
>
> > On 5月7日, 上午9时45分, Justin Ezequiel <justin.mailingli... at gmail.com>
> > wrote:
> >> On May 6, 5:19 pm, clyf... at gmail.com wrote:
>
> >> > p1 = Popen(['netstat', '-an'], stdout = PIPE)
> >> > p2 = Popen(['find',  '"445"'], stdin = p1.stdout, stdout = PIPE)
> >> > print p2.stdout.read()
>
> >> > It doesn't work.
> >> > Because subprocess.Popen execute "find" like this.
>
> >> > C:\>find \"445\"
>
> >> > It adds a '\' before each '"'.
> >> > How to remove the '\'?
> >> > Thank you.
>
> >> cannot help with the backslashes but try findstr instead of find
>
> > Thank you.
> > findstr doesn't need quotes, so it works.
>
> Build the command line yourself -instead of using a list of arguments-. Popen doesn't play with the quotes in that case:
>
> p1 = Popen(['netstat', '-an'], stdout = PIPE) # using list
> p2 = Popen('find "445"', stdin = p1.stdout, stdout = PIPE) # using str
> print p2.communicate()[0]
>
> --
> Gabriel Genellina

Thanks very much.
You solved my problem.



More information about the Python-list mailing list