execute commands independantly

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike Tammerman

    #1

    execute commands independantly

    Hi,

    I am trying to execute an executable or a pyton script inside my
    program. I looked at the subprocess and os module. But all the
    functions in these modules blocks my application. What I want to do is
    run the subprocess without any concern. I don't care of its return type
    or child signals. Just start and let it run independantly.

    Thanks,
    Mike

  • Leif K-Brooks

    #2
    Re: execute commands independantly

    Mike Tammerman wrote:[color=blue]
    > Hi,
    >
    > I am trying to execute an executable or a pyton script inside my
    > program. I looked at the subprocess and os module. But all the
    > functions in these modules blocks my application.[/color]

    subprocess doesn't block unless you call .wait():

    from subprocess import Popen
    proc = Popen('sleep 2; echo "Hello, world!"', shell=True)
    print "In two seconds, something will happen."
    proc.wait()
    print "Did you see that?"

    Comment

    • Rune Strand

      #3
      Re: execute commands independantly


      Mike Tammerman wrote:[color=blue]
      > I am trying to execute an executable or a pyton script inside my
      > program. I looked at the subprocess and os module. But all the
      > functions in these modules blocks my application. What I want to do is
      > run the subprocess without any concern. I don't care of its return type
      > or child signals. Just start and let it run independantly.[/color]

      If you don't need any output, os.system('app' ) should do.

      Comment

      • Eric McGraw

        #4
        Re: execute commands independantly


        If you want it to return when the program is finished then use
        os.system('app' ) but if you just want to start it and return right
        away, use os.startfile('a pp')

        Comment

        • Mike Tammerman

          #5
          Re: execute commands independantly

          You're right,

          I tried subprocess.call and os.spawn* functions. Popen is what I will
          be happy with.

          Thanks a lot.

          Mike

          Comment

          • Jorgen Grahn

            #6
            Re: execute commands independantly

            On 6 Sep 2005 08:07:12 -0700, Eric McGraw <thelinuxmaster @gmail.com> wrote:[color=blue]
            >
            > If you want it to return when the program is finished then use
            > os.system('app' ) but if you just want to start it and return right
            > away, use os.startfile('a pp')[/color]

            That one is Windows-only, though -- at least in 2.3 where I live. The
            os.spawn* family of calls are more portable, but I'm not sure it's a good
            idea to just spawn-and-forget a process.

            /Jorgen

            --
            // Jorgen Grahn <jgrahn@ Ph'nglui mglw'nafh Cthulhu
            \X/ algonet.se> R'lyeh wgah'nagl fhtagn!

            Comment

            Working...