From ae7846887d1cf0b38235ff8f0be47436f73a0429 Mon Sep 17 00:00:00 2001 From: Joel Collins Date: Tue, 11 Feb 2020 17:31:56 +0000 Subject: [PATCH] Show output when shutting down --- .../api/v2/views/actions/system.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/openflexure_microscope/api/v2/views/actions/system.py b/openflexure_microscope/api/v2/views/actions/system.py index 631c5c79..df002df1 100644 --- a/openflexure_microscope/api/v2/views/actions/system.py +++ b/openflexure_microscope/api/v2/views/actions/system.py @@ -25,9 +25,14 @@ class ShutdownAPI(View): """ Attempt to shutdown the device """ - subprocess.Popen(["sudo", "shutdown", "-h", "now"]) + p = subprocess.Popen( + ["sudo", "shutdown", "-h", "now"], + stderr=subprocess.PIPE, + stdout=subprocess.PIPE, + ) - return "{}", 201 + out, err = p.communicate() + return {"out": out, "err": err}, 201 @ThingAction @@ -41,6 +46,11 @@ class RebootAPI(View): """ Attempt to reboot the device """ - subprocess.Popen(["sudo", "shutdown", "-r", "now"]) + p = subprocess.Popen( + ["sudo", "shutdown", "-r", "now"], + stderr=subprocess.PIPE, + stdout=subprocess.PIPE, + ) - return "{}", 201 + out, err = p.communicate() + return {"out": out, "err": err}, 201