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

BlueBird phil at freehackers.org
Tue May 6 10:31:49 EDT 2008


On May 6, 11:19 am, clyf... at gmail.com wrote:
> In cmd, I can use find like this.
>
> C:\>netstat -an | find "445"
>   TCP    0.0.0.0:445            0.0.0.0:0              LISTENING
>   UDP    0.0.0.0:445            *:*
>
> C:\>
>
> And os.system is OK.>>> import os
> >>> os.system('netstat -an | find "445"')
>
>   TCP    0.0.0.0:445            0.0.0.0:0              LISTENING
>   UDP    0.0.0.0:445            *:*
> 0
>
>
>
> But I don't know how to use subprocess.Popen to do this.
>
> from subprocess import Popen, PIPE
>
> p1 = Popen(['netstat', '-an'], stdout = PIPE)
> p2 = Popen(['find',  '"445"'], stdin = p1.stdout, stdout = PIPE)
> print p2.stdout.read()
>

I would say that, according to documentation, the following should
work:
print p2.communicate()[0]


    Philippe



More information about the Python-list mailing list