View difference between Paste ID: wpeYLq5r and bWRmjvBG
SHOW: | | - or go back to the newest paste.
1
def process_file(filename, protocol):
2
   output_filename = '{0}-{1}.pcap'.format(filename, protocol)
3
   stdout_filename = '{0}.stdout'.format(filename)
4
   stderr_filename = '{0}.stderr'.format(filename)
5
   exitcode_filename = '{0}.exitcode'.format(filename)
6
7-
   cmdline = ['tshark', '-r', filename, '-Y', protocol, '-w', output_filename]
7+
   cmdline = ['tshark', '-r', filename, '-Y', protocol, 'P', '-w', output_filename]
8
   print('Command line: {0}'.format(repr(cmdline)))
9
10
   stdout_file = open(stdout_filename, 'w')
11
   stderr_file = open(stderr_filename, 'w')
12
   exitcode_file = open(exitcode_filename, 'w')
13
   exit_code = None
14
   try:
15-
       process = subprocess.Popen(cmdline,
15+
       shell_cmdline = ' '.join(cmdline)
16
       process = subprocess.Popen(shell_cmdline,
17
                                  stdin=subprocess.PIPE,
18-
                                  stderr=stderr_file)
18+
19
                                  stderr=stderr_file,
20
                                  shell=True)
21
       process.stdin.close()
22
       exit_code = process.wait()
23
   except:
24
       # Exception raised while waiting on process; kill child process,
25
       # then re-raise exception.
26
       exit_code = process.poll()
27
       process.kill()
28
       raise
29
   finally:
30
       # These file handles should have been closed already, but it doesn't hurt
31
       # to close them again.
32
       stdout_file.close()
33
       stderr_file.close()
34
       exitcode_file.write('%s\n' % str(exit_code))
35
       exitcode_file.close()
36
37
def thread_worker():
38
   while True:
39
       try:
40
           filename, protocol = global_q.get_nowait()
41
           print("Processing " + filename + "\n")
42
           process_file(filename, protocol)
43
           global_q.task_done()
44
       except queue.Empty:
45
           break