how to use subprocess.Popen execute "find" in windows
Diez B. Roggisch
deets at nospam.web.de
Tue May 6 07:33:42 EDT 2008
clyfish 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.
While there certainly are valid usecases for piping with subprocess in
Python - this ain't one I'd say. Just read the output of netstat yourself,
and filter for lines that contain the desired pattern.
Diez
More information about the Python-list
mailing list