earlier today this code worked as I wanted it to. Now it doesn’t. I want it to run airodump and store the output to a csv file (command line option). After a few seconds kill the process.
def find_networks():
airodump = subprocess.Popen(["airodump-ng","-w","airo","--output-format","csv","mon0"],stdout=subprocess.PIPE, stderr=subprocess.PIPE)
time.sleep(10)
try:
os.kill(airodump.pid, signal.SIGTERM)
if not airodump.poll():
print "shouldn't have had to do this.."
airodump.kill()
if not airodump.poll():
print "shouldn't have had to do this....."
airodump.terminate()
if not airodump.poll():
print "shouldn't have had to do this........"
except OSError:
print "?"
pass
except UnboundLocalError:
print "??"
pass
return_code = airodump.wait()
print return_code
(the output here is:
shouldn’t have had to do this..
shouldn’t have had to do this…..
-9)
Earlier it would do exactly what I said (same code). The negative 9 is worrisome, earlier I was getting 1, but the process still DOES die which is all thats important, but not due to os.kill statement, which is wierd. That’s not the big problem though. All i need is that .csv file. With this implementation, the csv file is completely empty – it is made but nothing ever put in it. If I run subprocess without stdout set to PIPE, the csv file IS created and populated, but I cant do it that way- I have to keep the stdout off the screen though.
Is stdout=subprocess.PIPE causing the data to be “written” to a nonexistent csv file in PIPE-land???
It’s difficult to reproduce what’s happening on your machine with your example code. One thing that might be causing some problems though: You should only use
stdout=subprocess.PIPEif you are actually intending to read from the pipe. If you don’t, the process will block once it generates enough output to fill up the pipe buffer.If all you want to do is to hide stdout and stderr, you can do this:
Or better yet:
Or if you are using Python 3, you can use subprocess.DEVNULL.