X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;ds=sidebyside;f=bin%2Fmc_type.py;h=d2e98843390068e52df3e42f8c9ae01a12eff465;hb=HEAD;hp=8292646646afc972baa3ea59dc829a15d8a30a65;hpb=e28540e371a02e7bc6b8e1fc3fa33eb842db09aa;p=dotfiles.git diff --git a/bin/mc_type.py b/bin/mc_type.py index 8292646..d2e9884 100755 --- a/bin/mc_type.py +++ b/bin/mc_type.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 import sys, subprocess @@ -7,12 +7,15 @@ assert mc in ['/usr/local/bin/mc', '/usr/bin/mc'] mc = subprocess.Popen([mc, '--version'], stdout=subprocess.PIPE, - stderr=subprocess.STDOUT) -mc.wait() -mc_version = mc.stdout.readline() -mc.stdout.read() -mc.stdout.close() + stderr=subprocess.PIPE, + close_fds=True, env={}) +stdout, stderr = mc.communicate() +if mc.returncode or stderr: + sys.exit('Error reading mc version: (%d) %s' % (mc.returncode, stderr)) +if not isinstance(stdout, type('')): + stdout = stdout.decode() +mc_version = stdout.split('\n')[0] if mc_version.startswith('Midnight Commander'): mc_version = mc_version.split()[2] elif mc_version.startswith('GNU Midnight Commander') or \