This is a static archive of our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

Write dumpcap stdout to a text file using python

0

I am currently trying to parse the filename from dumpcap's stdout in order to set it to a variable within my python script.
def startdump(): global DUMPCAP #global dumpdirectory global eventfile setDumpcapOptions() # Function that sets DUMPCAP = dumpcap -b duration:2147483647 -c 100 -i 1 -n -p -s 2 -w test3 -B 20 print("dumpcap.exe = " + DUMPCAP) #os.chdir(dumpdirectory) proc1 = subprocess.Popen(DUMPCAP, shell=True, stdout=subprocess.PIPE) if dc_mode == "Dumpcap Only": time.sleep(5) with open("proc1stdout.txt", 'w+') as proc1stdout: proc1stdout.write(str(proc1.stdout)) for line in proc1stdout: print("%s" % line) if "File:" in line: print(line) eventfile = line.split('File:')[1] print(eventfile) mail_man() proc1.communicate()

This gives me an error [Errno 2] No such file or directory: ''

I am coding in Python2.6.6. The Popen module does not support iterating so I cannot parse directly from the stdout in the terminal. Is there a way to write the Dumpcap stdout to a text file so that I can much more easily parse it from there?

asked 27 Jul '15, 08:29

Googlesomething's gravatar image

Googlesomething
11114
accept rate: 0%

edited 27 Jul '15, 08:48

cmaynard's gravatar image

cmaynard ♦♦
9.4k1038142


One Answer:

1

Dumpcap writes the filename to stderr, not stdout.

answered 27 Jul '15, 08:46

cmaynard's gravatar image

cmaynard ♦♦
9.4k1038142
accept rate: 20%