LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 01-25-2011, 03:04 PM   #1
daweefolk
Member
 
Registered: Sep 2009
Distribution: debian
Posts: 79

Rep: Reputation: 15
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?
 
Old 01-25-2011, 03:11 PM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
You can try os.environ, e.g.
Code:
username = os.environ.get("USER")
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pass the variable contain lrios Programming 7 04-18-2008 05:56 PM
varied output for linux df and du commands on same file system bzlaskar Linux - Newbie 1 12-11-2007 10:41 PM
perl: send output of system() call to variable drkstr Programming 4 07-23-2006 11:47 PM
Planning to change root pass and oracle system pass sathyguy Red Hat 1 12-20-2005 10:53 PM
in C, Assigning output of system() to a variable Miaire Programming 4 01-30-2005 01:40 PM


All times are GMT -5. The time now is 08:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration