From 130b43bd469148e9961e71c26ed8a9b3bb42fce1 Mon Sep 17 00:00:00 2001 From: Compiler Date: Sun, 27 Nov 2022 13:34:47 +0100 Subject: [PATCH] Fixed subprocess code --- __pycache__/main.cpython-311.pyc | Bin 5139 -> 5148 bytes main.py | 9 ++++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/__pycache__/main.cpython-311.pyc b/__pycache__/main.cpython-311.pyc index 6d4a8c55dc4e5e0083a2ecf977bcb2b30bf72fc4..093220e2285a50dcd1db1459149141fe8b333c6a 100644 GIT binary patch delta 300 zcmbQNF-L=UIWI340}!}GHYe+Br5Kzll z!|(sB(=9%ZLvRVb;kZeQrd;w!V6qQ7rBbAa1}K;KM)j|BGr-K;C6#su)%k-p}-7A zpUI~L@)(0ATMEiDCTsuC delta 324 zcmbQEF8&IGCD8>$^CK}e**>njHXpF~gGjK~!% z7i4s|Ms0~d8+9iBLUQ^A-i(X98CQ5S8r&WTNlekbz^~Zg4uVBeKr=MeZwaJMb`j`f z^qzcKAWt4-L6Ibg0Lg;w|HWaGo1apelWJF#usK1njmb=ifr+(Uyh*%6{34^^6-L1i XOq`6$9~gkdM`i{lAruj?FxW5vK4)EM diff --git a/main.py b/main.py index ba03897..4f7e43e 100644 --- a/main.py +++ b/main.py @@ -71,6 +71,8 @@ async def update_post(id: int, post: Post): my_posts[index] = post_dict return {"data": post_dict} + + @app.get("/list") async def ping_host(): # send one packet of data to the host @@ -78,7 +80,8 @@ async def ping_host(): outputlist = [] # Iterate over all the servers in the list and ping each server # get the output as a string - # output = str(os.system(cmd)) - output = subprocess.run(["/bin/ls", "-l"],stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + #output = str(os.system(cmd)) + cmd = subprocess.run(["/bin/ls", "-al"],stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True, text=True) # store the output in the list - output2 = (f"{output.stdout}") \ No newline at end of file + output = (f"{cmd.stdout}") + return output \ No newline at end of file