Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 06-13-2003, 03:27 AM   #1
LQ Guru
Registered: Apr 2002
Location: Atlanta
Distribution: Gentoo
Posts: 1,280

Rep: Reputation: 47
python, executing regular linux commands

how would i go about getting python to execute a command like "ls" (to list the files) or "ifconfig -a" to get information about the network interfaces.
In C there is the system() function, is there an equiv. in python? Did some googling but coudnt find it.
Old 06-14-2003, 12:13 AM   #2
LQ Guru
Registered: Apr 2002
Location: Atlanta
Distribution: Gentoo
Posts: 1,280

Original Poster
Rep: Reputation: 47
13 hits, no response, and i still cant find it either.
Old 06-14-2003, 04:52 AM   #3
Senior Member
Registered: Dec 2002
Location: England
Distribution: Used to use Mandrake/Mandriva
Posts: 2,794

Rep: Reputation: 116Reputation: 116
exec(command) ?
All types explained in Process Management from the online Modules Index. You have a copy on your pc when you install Python
Old 06-26-2003, 04:35 PM   #4
Registered: Jun 2003
Distribution: Fedora Core 2
Posts: 37

Rep: Reputation: 15
It's been a while since you posted, so you've probably found your answer. But, just in case you haven't, here you go.

There are a few different ways to do it, depending on what you need. Check out the python documentation on their usage, etc. They are all from the os module:

os.system('<your command'>. It will just execute the command and return an exit status.

The os.exec* variants and the os.spawn* variants. Read about them here.

Hope that helps!!!


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
Python - need help narrowing a regular expression rose_bud4201 Programming 2 10-30-2005 01:37 AM
Regular Expressions in Python indian Programming 7 09-15-2005 12:00 AM
executing shell commands in c++ true_atlantis Programming 2 10-01-2004 05:53 PM
Executing Linux commands in C programs--->please help dennyvm Programming 3 01-15-2004 11:51 AM
Executing commands on startup viciousfish Linux - General 5 06-28-2002 03:15 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:16 PM.

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