I am trying to grab the stdout from airodump-ng using subprocess with no luck.
I think my code causes a deadlock.
airodump = subprocess.Popen(['airodump-ng','mon0'],stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
# wait for 15 seconds to find all networks
time.sleep(15)
# save the output
o_airodump = airodump.stdout.read()
os.kill(airodump.pid, signal.SIGKILL)
# airodump.terminate
print(o_airodump)
How to avoid this problem. Cant think one clean solution.
Don’t sleep and wait (that will just cause airodump to block on a full pipe buffer) and don’t use an unbounded read(). The communicate() method does what you need:
Note: The timeout parameter on communicate was introduced in Python 3.3 which isn’t quite out yet. 😉