shell - python subprocess and reading stdout -


what proper way of reading subprocess , stdout

here files:

traffic.sh code.py 

traffic.sh:

sudo tcpdump -i lo -a | grep host: 

code.py:

proc = subprocess.popen(['./traffic.sh'], stdout=subprocess.pipe, stderr=subprocess.pipe, shell=true) # network stuff ping places, send email, open few web pages , wait them finish loading # stop traffic , make sure on data = proc.stdout.read() proc.kill() 

the code above works , doesnt.

the times fails, due getting stuck on proc.stdout.read().

i have followed bunch of examples recommend setup thread , queue proc , read queue proc writes. however, turnout intermittent how works.

i feel im doing wrong kill , read. because can guarantee there no communication happening on lo when make call , therefore, traffic.sh should not printing out @ all.

then why read blocking.

any clean alternative thread?

edit have tried this, in hope read no longer block since process terminated

proc = subprocess.popen(['./traffic.sh'], stdout=subprocess.pipe, stderr=subprocess.pipe, shell=true) # network stuff ping places, send email, open few web pages , wait them finish loading # stop traffic , make sure on proc.kill() data = proc.stdout.read() 


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -