C
clyfish
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. 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()
It doesn't work.
Because subprocess.Popen execute "find" like this.
C:\>find \"445\"
¾Ü¾ø·ÃÎÊ - \
C:\>
It adds a '\' before each '"'.
How to remove the '\'?
Thank you.
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. 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()
It doesn't work.
Because subprocess.Popen execute "find" like this.
C:\>find \"445\"
¾Ü¾ø·ÃÎÊ - \
C:\>
It adds a '\' before each '"'.
How to remove the '\'?
Thank you.