LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   python: how to pass output of system commands to variable (https://www.linuxquestions.org/questions/programming-9/python-how-to-pass-output-of-system-commands-to-variable-858618/)

daweefolk 01-25-2011 02:04 PM

python: how to pass output of system commands to variable
 
I'm trying to write a python script that will use the current user's name when interacting. Ex: when started, it should say "hello daweefolk" when I am logged in.
I've tried
Code:

username=os.system("echo $USER")
but the variable remains empty.
What is the correct code?

colucix 01-25-2011 02:11 PM

You can try os.environ, e.g.
Code:

username = os.environ.get("USER")


All times are GMT -5. The time now is 05:55 AM.