[Tutor] os.popen - using commands and input %

Vusa Moyo soweto at gmail.com
Mon Nov 16 07:17:00 EST 2015


Hi Guys,

OS = SuSE Enterprise Linux
Python V2.7

My code is as follows

# this list contains system process ID's
pidst=[1232, 4543, 12009]

pmap_str=[]
command="pmap -d %s | grep private |awk '{print $1}' | awk -FK '{print $1}'"

for i in range(len(pids)):
    pmap_str.append(os.popen("(command) % pidlist_int[i])"))     # <--
this is where I need help, please

As I'm sure you can see, I'm trying to output the os.popen output to a new
list.

On the shell console I can run the pmap command as follows

pmap -d <PID> | grep private |awk '{print $1}' | awk -FK '{print $1}'

Output will be a single number such as 485921.

My error is on the line of code shown above. Please assist.

Kind Regards


More information about the Tutor mailing list