Я хочу проверить, успешно ли завершено выполнение подпроцесса или нет. В настоящее время я нашел решение, но я не уверен, что оно правильное и надежное. Гарантируется ли, что каждый процесс выводит свои ошибки только в stderr с уважением к stdout
:
Примечание: меня не интересует просто перенаправление/распечатка вывода. Это я уже знаю, как это сделать.
pipe = subprocess.Popen(command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True)
if "" == pipe.stdout.readline():
print("Success")
self.isCommandExectutionSuccessful = True
if not "" == pipe.stderr.readline():
print("Error")
self.isCommandExectutionSuccessful = True
альтернативно:
if "" == pipe.stdout.readline():
print("Success")
self.isCommandExectutionSuccessful = True
else:
print("Error")
self.isCommandExectutionSuccessful = False
а также:
if not "" == pipe.stderr.readline():
print("Success")
self.isCommandExectutionSuccessful = True
else:
print("Error")
self.isCommandExectutionSuccessful = False