I’ve seen various other posts about this, but unfortunately I still haven’t been able to figure this out:
If I do something like this:
temp = subprocess.Popen("whoami", shell=True, stdout=subprocess.PIPE)
out = temp.communicate()
print(out)
then I get something of the form
(b'username\n', None)
With other attempts (such as adding a .wait()) I’ve been getting the username on one line, and a 0 as a return code on the next, however only the 0 was being stored in my variable.
Is there an easy way I can format that to store only the username in a variable? I tried something like out[3:11] but that didn’t work.
Thanks
The easiest way is to use
subprocess.check_output():