From 32aa1d70601e9dfc62349c67633caaf59952eff7 Mon Sep 17 00:00:00 2001 From: Krasimir Mikov <91935581+kmikov@users.noreply.github.com> Date: Tue, 11 Feb 2025 22:02:52 +0200 Subject: [PATCH] Update tshark.py Fix version parsing when the version number is not on the first line due to plugins. --- src/pyshark/tshark/tshark.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/pyshark/tshark/tshark.py b/src/pyshark/tshark/tshark.py index 73ede9dc..2eb31243 100644 --- a/src/pyshark/tshark/tshark.py +++ b/src/pyshark/tshark/tshark.py @@ -82,13 +82,16 @@ def get_tshark_version(tshark_path=None): with open(os.devnull, "w") as null: version_output = subprocess.check_output(parameters, stderr=null).decode("ascii") - version_line = version_output.splitlines()[0] + version_lines = version_output.splitlines() + version_string = None pattern = r'.*\s(\d+\.\d+\.\d+).*' # match " #.#.#" version pattern - m = re.match(pattern, version_line) - if not m: - raise TSharkVersionException("Unable to parse TShark version from: {}".format(version_line)) - version_string = m.groups()[0] # Use first match found - + for version_line in version_lines: + m = re.match(pattern, version_line) + if m: + version_string = m.groups()[0] # Use first match found + break + if not version_string: + raise TSharkVersionException("Unable to parse TShark version from: {}".format(version_lines)) return version.parse(version_string)