Fixed subprocess code

This commit is contained in:
2022-11-27 13:34:47 +01:00
parent 337ca690cf
commit 130b43bd46
2 changed files with 6 additions and 3 deletions

View File

@ -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}")
output = (f"{cmd.stdout}")
return output