In this code, I am using os.popopen
to run a background system command.
import os
user = "g"
def fetch(): # Gets all the system info via os.system and stores them in variables
user = os.popen("""whoami""").read()
fetch()
print(user)
input()
You will see that user is first equal to g, normally this is equal to just (" ") but I put it to g to demonstrate. My code should be running my fetch()
function but it is ether failing bts or my function is not being called, beucase user is always equal to whatever it was before the function (in this case, g). I ran all these lines in the python console and there it works, which makes this really frustrating. What is happening?
(before anyone says anything about how I should be using subprocesses
, that does not work in my case.)