how to capture os.execvp into variable

S

s99999999s2003

hi
i am using this code to run a ps command in unix

def run(program, *args):
pid = os.fork()
if not pid:
os.execvp(program, (program,) + args)
return os.wait()[0]

run("ps", "-eo pid,ppid,args")

It runs fine, but i wish to store the results into a variable....how
can i do this ? I tried
to put ret=os.execvp(program, (program,) + args) but ret has no value
thanks
 
B

Ben C

hi
i am using this code to run a ps command in unix

def run(program, *args):
pid = os.fork()
if not pid:
os.execvp(program, (program,) + args)
return os.wait()[0]

run("ps", "-eo pid,ppid,args")

It runs fine, but i wish to store the results into a variable....how
can i do this ? I tried
to put ret=os.execvp(program, (program,) + args) but ret has no value
thanks

Do you mean you want the output of ps? That seems most likely. In that
case use os.popen.

p = os.popen("ps -eo pid,ppid,args")
output = p.read()
p.close()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top