Skip to content

Commit

Permalink
Workaround for old dialog versions that print the version on stdout
Browse files Browse the repository at this point in the history
* dialog.py: some dialog versions print the version on stdout when using
--print-version (e.g., 1.1-20100428). In this case, the output read on
stderr is empty. This commit works around this problem by rerunning the
dialog program, capturing its stdout instead of stderr. The penalty is
minimal since the backend version is cached.
  • Loading branch information
frougon committed Apr 3, 2015
1 parent 1d0ee25 commit 07a216b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion dialog.py
@@ -1,7 +1,7 @@
# dialog.py --- A Python interface to the ncurses-based "dialog" utility
# -*- coding: utf-8 -*-
#
# Copyright (C) 2002, 2003, 2004, 2009, 2010, 2013, 2014 Florent Rougon
# Copyright (C) 2002, 2003, 2004, 2009, 2010, 2013, 2014, 2015 Florent Rougon
# Copyright (C) 2004 Peter Åstrand
# Copyright (C) 2000 Robb Shecter, Sultanbek Tezadov
#
Expand Down Expand Up @@ -1656,6 +1656,19 @@ def backend_version(self):
"""
code, output = self._perform(["--print-version"],
use_persistent_args=False)

# Workaround for old dialog versions
if code == self.OK and not (output.strip() or self.use_stdout):
# output.strip() is empty and self.use_stdout is False.
# This can happen with old dialog versions (1.1-20100428
# apparently does that). Try again, reading from stdout this
# time.
self.use_stdout = True
code, output = self._perform(["--stdout", "--print-version"],
use_persistent_args=False,
dash_escape="none")
self.use_stdout = False

if code == self.OK:
try:
mo = self._print_version_cre.match(output)
Expand Down

0 comments on commit 07a216b

Please sign in to comment.