0

How would I execute a command and have it's output returned as a list or string? For example (in Linux):

os.system("iwconfig")

prints a list of wireless devices to stdout. How can I make Python see those results as a list or string so I can search for certain devices (like wlan0 for example) and their associated info?

3
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by txwooley
0

Which module contains "Command"? I can't find it in os, sys or subprocess. I get an error that "name 'Command' is not defined".

0

AWESOME!! I see you wrote that too. Great job and thanks for the pointer in the right direction!

0

oh BTW just got summin to add.
I no ur linux and im win7 64-bit but hey...

i use:

import os

strng = os.system('dir') #using dir as example - a cmd function
print string #show us
os.system('pause') #give us time to reeeeeaaaaadddddd.

i no ive only done it as basic variable but u shud b able 2 play wif it.
i cant c y it shouldnt work on linux...

0

oh BTW just got summin to add.
I no ur linux and im win7 64-bit but hey...

i use:

import os

strng = os.system('dir') #using dir as example - a cmd function
print string #show us
os.system('pause') #give us time to reeeeeaaaaadddddd.

i no ive only done it as basic variable but u shud b able 2 play wif it.
i cant c y it shouldnt work on linux...

The return value of os.system depends on your OS, and the python documentation explicitly recommends using the subprocess module instead.

Edited by Gribouillis: n/a

0

oh BTW just got summin to add.
I no ur linux and im win7 64-bit but hey...

i use:

import os

strng = os.system('dir') #using dir as example - a cmd function
print string #show us
os.system('pause') #give us time to reeeeeaaaaadddddd.

i no ive only done it as basic variable but u shud b able 2 play wif it.
i cant c y it shouldnt work on linux...

I tried that first. On Linux, os.system returns an integer (0 for True and oddly enough 246 for False). So it doesn't actually return the output, just the exit code.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.