Я пытаюсь запустить команду в Python, которая запускает исполняемый файл, а затем я хочу получить файл журнала.Я использовал subprocess.popen
, а затем subprocess.communicate
, но получил ошибку: Неверный объект файла.Вот мой код:
command = "%s -s/test_scripts/tests/unit_tests.csh list_tests=yes list_groups=yes" % (PATH)
print(command)
os.popen(command)
p = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
try:
text = p.communicate(timeout=600)[0]
Вот сообщение об ошибке, которое я получил:
File "/disk/incam/test_scripts/run_all_tests-linux.py", line 249, in <module>
text = p.communicate(timeout=20)[0]
File "/opt/lib/python3.7/subprocess.py", line 933, in communicate
stdout, stderr = self._communicate(input, endtime, timeout)
File "/opt/lib/python3.7/subprocess.py", line 1666, in _communicate
selector.register(self.stdout, selectors.EVENT_READ)
File "/opt/lib/python3.7/selectors.py", line 352, in register
key = super().register(fileobj, events, data)
File "/opt/lib/python3.7/selectors.py", line 238, in register
key = SelectorKey(fileobj, self._fileobj_lookup(fileobj), events, data)
File "/opt/lib/python3.7/selectors.py", line 225, in _fileobj_lookup
return _fileobj_to_fd(fileobj)
File "/opt/lib/python3.7/selectors.py", line 40, in _fileobj_to_fd
"{!r}".format(fileobj)) from None
ValueError: Invalid file object: <_io.BufferedReader name=4>
Если кто-нибудь знает, как решить эту проблему, я хотел бы услышать.Спасибо.