Merge pull request #9 from makermelissa/master
Fix error output was missing
This commit is contained in:
commit
82deb93889
1 changed files with 28 additions and 23 deletions
|
|
@ -63,30 +63,35 @@ class Shell:
|
||||||
"""
|
"""
|
||||||
Run a shell command and show the output as it runs
|
Run a shell command and show the output as it runs
|
||||||
"""
|
"""
|
||||||
proc = subprocess.Popen(
|
original_stdout = sys.stdout
|
||||||
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
original_stderr = sys.stderr
|
||||||
)
|
try:
|
||||||
full_output = ""
|
proc = subprocess.Popen(
|
||||||
while True:
|
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
||||||
output = proc.stdout.readline()
|
)
|
||||||
if len(output) == 0 and proc.poll() is not None:
|
full_output = ""
|
||||||
break
|
while True:
|
||||||
if output:
|
output = proc.stdout.readline()
|
||||||
decoded_output = output.decode("utf-8", errors="ignore").strip()
|
err = proc.stderr.read()
|
||||||
if not suppress_message:
|
if err and not suppress_message:
|
||||||
self.info(decoded_output)
|
self.error(err.decode("utf-8", errors="ignore"))
|
||||||
full_output += decoded_output
|
if len(output) == 0 and proc.poll() is not None:
|
||||||
r = proc.poll()
|
break
|
||||||
if r == 0:
|
if output:
|
||||||
if return_output:
|
decoded_output = output.decode("utf-8", errors="ignore").strip()
|
||||||
return full_output
|
if not suppress_message:
|
||||||
return True
|
self.info(decoded_output)
|
||||||
|
full_output += decoded_output
|
||||||
err = proc.stderr.read()
|
except Exception as err: # pylint: disable=broad-except
|
||||||
if not suppress_message:
|
pass
|
||||||
self.error(err.decode("utf-8", errors="ignore"))
|
finally:
|
||||||
|
sys.stdout = original_stdout
|
||||||
|
sys.stderr = original_stderr
|
||||||
if return_output:
|
if return_output:
|
||||||
return full_output
|
return full_output
|
||||||
|
r = proc.poll()
|
||||||
|
if r == 0:
|
||||||
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def info(self, message):
|
def info(self, message):
|
||||||
|
|
@ -453,7 +458,7 @@ class Shell:
|
||||||
if os.path.exists("/etc/os-release"):
|
if os.path.exists("/etc/os-release"):
|
||||||
with open("/etc/os-release") as f:
|
with open("/etc/os-release") as f:
|
||||||
if "Raspbian" in f.read():
|
if "Raspbian" in f.read():
|
||||||
release = "Raspian"
|
release = "Raspbian"
|
||||||
if self.run_command("command -v apt-get", suppress_message=True):
|
if self.run_command("command -v apt-get", suppress_message=True):
|
||||||
with open("/etc/os-release") as f:
|
with open("/etc/os-release") as f:
|
||||||
release_file = f.read()
|
release_file = f.read()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue