how to capture os.execvp into variable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • s99999999s2003@yahoo.com

    #1

    how to capture os.execvp into variable

    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(progr am, (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(p rogram, (program,) + args) but ret has no value
    thanks

  • Ben C

    #2
    Re: how to capture os.execvp into variable

    On 2006-03-28, s99999999s2003@ yahoo.com <s99999999s2003 @yahoo.com> wrote:[color=blue]
    > 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(progr am, (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(p rogram, (program,) + args) but ret has no value
    > thanks[/color]

    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()

    Comment

    Working...