I'm trying to get the hostname where the .py is running, so I used:
server = subprocess.Popen(["hostname"])
print(server.stdout)
However, I'm getting this return:
None
HOSTNAME
It always prints a None from the subprocess.Popen() and then the hostname at print(server.stdout). Is there a way to fix this?
Nonefromprint(server.stdout)(because you didn't tell it to capture stdout), and the subprocess is sendingHOSTNAMEdirectly to your terminal. You need to add astdout=subprocess.PIPEparameter toPopen().<Popen: returncode: None args: ['hostname']>