Найти - Пользователи
Полная версия: subprocess.check_output: cannot use a string pattern on a bytes-like object
Начало » Python для новичков » subprocess.check_output: cannot use a string pattern on a bytes-like object
1
Imarden
Добрый день!
Пытаюсь проверить в python запущен ли процесс в виртуальной машине.
Пытаюсь переписать на Python https://github.com/jfcoz/postgresqltuner

 import re
import subprocess
test_variable = subprocess.check_output('dmesg',shell=True)
result = re.findall(r'vmware|kvm|xen|vbox|hyper-v', test_variable)
print(result)

Выдает ошибку:
TypeError: cannot use a string pattern on a bytes-like object
Как лучше написать чтобы проверить в python запущен ли процесс в виртуальной машине?
Спасибо
spikejke
TypeError: cannot use a string pattern on a bytes-like object
subprocess - вернул Вам объект типа bytes, необходимо декодировать его:
 result = re.findall(r'vmware|kvm|xen|vbox|hyper-v', test_variable.decode('utf-8'))
Imarden
Работает спасибо.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB