Fix use of Popen to make sure process cleanup happens.
@@ -272,8 +272,8 @@ class PCAPToCSV():
def get_tshark_packet_data(self, pcap_file, dict_fp):
options = '-n -V -Tjson'
try:
- process = subprocess.Popen(shlex.split(
- ' '.join(['tshark', '-r', pcap_file, options])), stdout=subprocess.PIPE)
+ with subprocess.Popen(shlex.split(
+ ' '.join(['tshark', '-r', pcap_file, options])), stdout=subprocess.PIPE) as process:
with gzip_writer(dict_fp) as f_out:
for item in self.json_packet_records(process):
f_out.write(json.dumps(self.flatten_json(item)) + '\n')
